PHP邮件发送不出去,如何调试?
我一直在尝试发送注册、邀请等电子邮件。
在本地开发中,会发送电子邮件。但是,一旦到达服务器,就不会收到任何邮件。
我安装了postfix。我曾尝试设置邮件服务器但放弃了。所以目前,如果我在终端输入
peter# mail [email protected]
电子邮件就会到达。但是,这不会发送电子邮件:
$res = mail('[email protected]', 'subj', 'bodddd');
不仅如此,回显 $res
也不会给出任何结果。既不是 true
也不是 false
。
我该怎么做才能让它发挥作用?
谢谢
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
.
What and how do i do to make it working?
thanx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您上面的评论,您的 sendmail 路径似乎错误或在 php.ini 中被注释掉。它应该是这样的:
如果您不确定 sendmail 二进制文件所在的位置,您可以使用以下命令找到它:
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:
If you're unsure where your sendmail binary resides, you may find it by using:
在共享主机上对我有用的解决方案是在
mail
函数中使用-f
附加参数。而不是 ...mail($to, $subject, $body, $headers);
我必须使用 ...
mail($to, $subject, $body, $headers , " [电子邮件受保护]");
根据 php手册 附加参数作为 sendmail 的附加参数提供。请注意,
-f
和电子邮件之间缺少空格似乎是故意的。就我而言,在一台特定主机上,我无法访问 postfix/sendmail 日志。原始命令返回 true,cpanel 日志显示它已被接受交付,但收件人从未收到它。
The solution that worked for me on shared hosting was to use the
-f
additional parameter in themail
function. Instead of ...mail($to, $subject, $body, $headers);
I had to use ...
mail($to, $subject, $body, $headers, " [email protected]");
According to the php manual the additional parameters are provides as additional arguments to sendmail. Note that the lack of space between
-f
and the email seems intentional.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.