PHP 邮件未发送,如何调试?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7912992/
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
PHP mail does not get sent, how do I debug?
提问by mgPePe
I have been trying to send email for registration, invitations and so on.
我一直在尝试发送电子邮件进行注册、邀请等。
On local development, emails get sent. However once on the server no mails arrive.
在本地开发中,会发送电子邮件。然而,一旦在服务器上没有邮件到达。
I installed postfix. I was trying to setup a mail server but gave up. So currently, If I type in terminal
我安装了后缀。我试图设置邮件服务器但放弃了。所以目前,如果我输入终端
peter# mail [email protected]
the email arrives. However, this does not send email:
电子邮件到达。但是,这不会发送电子邮件:
$res = mail('[email protected]', 'subj', 'bodddd');
not only that, but echoing $res
gives nothing. Neither true
nor false
.
不仅如此,而且 echoing$res
什么也没有。既不true
也不false
。
What and how do i do to make it working?
我该怎么做才能让它工作?
thanx
谢谢
回答by Oldskool
According to your comment above, it looks like your sendmail path is either wrong or commented out in your php.ini. It should be something like this:
根据您上面的评论,您的 sendmail 路径似乎是错误的,或者在您的 php.ini 中被注释掉了。它应该是这样的:
sendmail_path = /usr/sbin/sendmail -t -i
If you're unsure where your sendmail binary resides, you may find it by using:
如果您不确定您的 sendmail 二进制文件所在的位置,您可以使用以下方法找到它:
whereis sendmail
回答by drgrog
The solution that worked for me on shared hosting was to use the -f
additional parameter in the mail
function. Instead of ...
在共享主机上对我有用的解决方案是-f
在mail
函数中使用附加参数。代替 ...
mail($to, $subject, $body, $headers);
mail($to, $subject, $body, $headers);
I had to use ...
我不得不使用...
mail($to, $subject, $body, $headers, " [email protected]");
mail($to, $subject, $body, $headers, " [email protected]");
According to the php manualthe additional parameters are provides as additional arguments to sendmail. Note that the lack of space between -f
and the email seems intentional.
根据php 手册,附加参数作为附加参数提供给 sendmail。请注意,-f
电子邮件和电子邮件之间缺少空格似乎是故意的。
In my case on one particular host I did not have access to the postfix/sendmail logs. The original command returned true and a cpanel log showed it was accepted for delivery, however the recipient never received it.
就我而言,在一台特定主机上,我无法访问 postfix/sendmail 日志。原始命令返回 true 并且 cpanel 日志显示它已被接受交付,但收件人从未收到它。