PHP邮件发送不出去,如何调试?

发布于 2024-12-11 21:40:01 字数 660 浏览 0 评论 0原文

我一直在尝试发送注册、邀请等电子邮件。

在本地开发中,会发送电子邮件。但是,一旦到达服务器,就不会收到任何邮件。

我安装了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小ぇ时光︴ 2024-12-18 21:40:01

根据您上面的评论,您的 sendmail 路径似乎错误或在 php.ini 中被注释掉。它应该是这样的:

sendmail_path = /usr/sbin/sendmail -t -i

如果您不确定 sendmail 二进制文件所在的位置,您可以使用以下命令找到它:

whereis 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:

sendmail_path = /usr/sbin/sendmail -t -i

If you're unsure where your sendmail binary resides, you may find it by using:

whereis sendmail
星光不落少年眉 2024-12-18 21:40:01

在共享主机上对我有用的解决方案是在 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 the mail 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文