php mail() 在新服务器上不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14866207/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mail() doesn't work on new server
提问by Dima Deplov
May be it's a dumb question, but I can't find the reason why php mail function doesn't work I have a nginx server on debian squeeze, I moved to it recently. I tried simple mail execution but it return false.
可能这是一个愚蠢的问题,但我找不到 php 邮件功能不起作用的原因我在 debian 挤压上有一个 nginx 服务器,我最近搬到了它。我尝试了简单的邮件执行,但它返回 false。
if(mail('[email protected]', 'test-subject', 'test-text-blablabla'))
echo 'ok';
else
echo 'bad';
What can i do with it?
我可以用它做什么?
Thanks.
谢谢。
my mail section of php.ini:
我的 php.ini 邮件部分:
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = [email protected]
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =
; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_parameters =
; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
mail.add_x_header = On
; The path to a log file that will log all mail() calls. Log entries include
; the full path of the script, line number, To address and headers.
;mail.log =
回答by Dima Deplov
Okay, I made it. How I made it for debian squeeze with nginx server: (all commands I execute from root user)
好的,我做到了。我是如何使用 nginx 服务器为 debian挤压制作的:(我从 root 用户执行的所有命令)
First of all you need to install sendmail
首先你需要安装sendmail
apt-get install sendmail
next, you must configure this file that was easier than I thought
接下来,你必须配置这个比我想象的更容易的文件
sendmailconfig
okay, next step that I make was a php.ini configuration (I'm not a great admin, I'm a beginner, so I don't know is it necessary or not.)
好的,我做的下一步是 php.ini 配置(我不是一个伟大的管理员,我是一个初学者,所以我不知道是否有必要。)
I set
我设置
sendmail_path= /usr/sbin/sendmail -t -i
Okay, from this moment, theoretically, you can send email, but for my case it led to 504 http error gateway time-out. But as I found much later the email already came to email box. So, my test php file is:
好的,从现在开始,理论上,您可以发送电子邮件,但就我而言,它导致 504 http 错误网关超时。但正如我后来发现的那样,电子邮件已经进入邮箱。所以,我的测试 php 文件是:
<?php
mail('[email protected]', 'test', 'you done that');
echo 'ok'; // I use this to check that script is end the execution
?>
That's pretty clear.
这很清楚。
Next problem is 504 error. I go to the log files
下一个问题是 504 错误。我去日志文件
nano /var/log/mail.log
and here i find this error (that not the only one error, but that one is responsible for 504 error):
在这里我发现了这个错误(这不是唯一的一个错误,而是那个导致 504 错误的错误):
sm-msp-queue[***]: My unqualified host name (myhostname) unknown; sleeping for retry
Then, to find how I can solve this trouble: http://forums.fedoraforum.org/archive/index.php/t-85365.htmllast comment on that page.
然后,找到我如何解决这个问题:http: //forums.fedoraforum.org/archive/index.php/t-85365.html该页面上的最后一条评论。
Or another words I made this:
或者我说的另外一句话:
nano /etc/hosts
and in that file I change the order of the hosts
在那个文件中我改变了主机的顺序
127.0.0.1 my_ip localhost myhostname
save, done. open your test php file, there is no any 504 error and emails is income to email you mention in mail function. As I say, I'm a novice, and that may not work for you, but it work for me anyhow. This is not the end configuration, of course. Hope you find it helpful.
保存,完成。打开您的测试 php 文件,没有任何 504 错误,电子邮件是您在邮件功能中提到的电子邮件的收入。正如我所说,我是新手,这可能对你不起作用,但无论如何它对我有用。当然,这不是最终配置。希望你觉得它有帮助。

