问题描述
转移到新主机后,我开始遇到一些奇怪的问题。
After moving to new hosting, I've started having strange issues.
PHP mail()函数仅在将以下行添加到php.ini中时才有效使用-f参数。
(如果省略-f参数,mail()函数将返回true,但不执行任何操作。)
PHP mail() function only works, if I add the following line to php.ini with -f parameter.(If I omit -f parameter, mail() function will return true, but do nothing.)
[mail function]
sendmail_path = "/usr/sbin/sendmail -t -i -f [email protected]"
但是,这会导致所有消息具有以下不良标头:
This, however, causes all messages have the following undesirable header:
Return-Path: <[email protected]>
我尝试在mail()中添加第五个参数,但是没有效果。
I've tried adding fifth argument to mail(), however it has no effect.
非常感谢您的帮助。
预先感谢!
I would highly appreciate your help.Thanks in advance!
推荐答案
要检查/更改您的PHP邮件配置:
To check/change your PHP mail configuration:
打开您的php.ini文件(如果您不知道它在哪里,请参阅下文)搜索显示为[mail function]的行。添加/更改邮件服务器的详细信息。这可能是本地邮件服务器或ISP的邮件服务器。保存/关闭php.ini文件重新启动Web服务器
Open your php.ini file (if you don't know where this is, see below) Search for the line that reads [mail function] Add/change the details of your mail server. This could be a local mail server or the mail server of your ISP. Save/close the php.ini file Restart your web server
首次打开php.ini文件时邮件设置的示例:
An example of what the mail settings could look like when you first open the php.ini file:
[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25
; For Win32 only.
;sendmail_from = [email protected]
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;sendmail_path =
其他信息正在回显 phpinfo()
,您可以查看您的PHP配置详细信息。您可以通过创建带有以下行的.php文件来实现此目的:。在浏览器中运行此命令时,将看到PHP配置变量的完整列表。只需搜索包含php.ini和sendmail_path的行即可查看您需要使用的值。
Additional info is in echoing phpinfo()
you can view your PHP configuration details. You can do this by creating a .php file with the following line on it: . When you run this in your browser, you will see a full list of PHP configuration variables. Simply search for the lines that contain php.ini and sendmail_path to see the values you need to use.
另一个想法是您可以使用 ini_set( )
像这样正确配置您的邮件设置
Another idea is you might use ini_set()
to properly config your mail setting like this
如果您的邮件脚本继续失败,请在电子邮件脚本顶部添加以下代码。
Add the following code to the top of your email script if your mail script continues to fail.
// Please specify your Mail Server - Example: mail.example.com.
ini_set("SMTP","mail.example.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', '[email protected]');
这篇关于PHP mail()返回路径问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!