PHP 邮件停止工作 [英] PHP mail stopped working

查看:25
本文介绍了PHP 邮件停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天前在使用 mail() 时我让它工作了.

Some days ago when using mail() I had it working.

但是现在不行了.而且我不知道是什么问题.

But now it doesn't work. And I don't know what the problem is.

$to      = 'testmail@gmail.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: sender@gmail.com' . "
" .
    'Reply-To: sender@gmail.com' . "
" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

$mail_sent = @mail( $to, $subject, $message, $headers ); 
echo $mail_sent ? "Mail sent" : "Mail failed";

显示邮件已发送".

我没有接触过 Apache 或这段代码中的任何内容.我在一个空的 PHP 文件中测试了代码,结果相同.我该如何调试这个问题?

I haven't touched anything in Apache or this code. I have tested the code in an empty PHP file with the same result. How can I debug this problem?

推荐答案

可能是电子邮件发送正常,但被垃圾邮件过滤器捕获?如果可以,请允许我交叉发布自己:

Could it be that E-Mails are being sent fine, but are caught by a spam filter? If this could be, allow me to cross-post myself:

一些要点(假设 mail() 返回 true 并且错误日志中没有错误):

A few bullet points (Assuming that mail() returns true and there are no errors in the error log) :

  • 发件人地址(发件人")是否属于您服务器上的域?如果没有,就让它这样.
  • 您的服务器是否在黑名单上(例如在 spamhaus.org 上检查 IP)?这是共享主机的远程可能性.
  • 邮件是否被垃圾邮件过滤器过滤?使用带有垃圾邮件文件夹的免费邮件程序打开一个帐户并找出答案.此外,尝试将邮件发送到没有垃圾邮件过滤器的地址.
  • 您是否可能需要mail() 的第五个参数-f"来添加发件人地址?(参见 PHP 手册中的 mail() 命令)
  • 如果您有权访问日志文件,当然可以按照上面的建议检查这些文件.
  • 您是否检查发件人:"地址以查找可能的退回邮件(退回给发件人")?您还可以设置一个单独的errors-to"地址.

对于讲德语的人,我前段时间写了一篇关于这个问题的非常详尽的该怎么做".请参阅此处.

For german speakers, I have written a quite exhaustive "what to do" on this issue some time ago. See here.

这篇关于PHP 邮件停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆