简体   繁体   English

PHP Mail():如何获取有关使用php mail()发送邮件失败的更多信息。

[英]PHP Mail() : how to get more information regarding failure of sending mails using php mail().

如果php mail()无法发送邮件,有什么方法可以使我们知道失败的确切原因是什么。

From a quick look, I was not able to find any way to catch errors generated by mail() . 快速浏览后,我找不到任何方法来捕获mail()生成的错误。 The easiest way would be to use error_get_last , to collect the last error that has occurred. 最简单的方法是使用error_get_last来收集最近发生的错误。 However, you should do this once mail() returns false . 但是,一旦mail()返回false ,就应该这样做。

Another possible solution would be to set_error_handler and when you send a mail, and then immediately remove the handler after you send the mail. 另一种可能的解决方案是在发送邮件时使用set_error_handler,然后在发送邮件后立即删除处理程序。 Then, your error handler should be able to catch any errors/warnings/notices that has occured while sending the mail. 然后,您的错误处理程序应该能够捕获发送邮件时发生的任何错误/警告/通知。

Using a library like swiftmailer would be much more flexible as it would allow you to catch its errors and exceptions easily. 使用诸如swiftmailer之类的库将更加灵活,因为它可以使您轻松捕获其错误和异常。

If you are talking about errors on the receiving server, then you need to implement VERP or some sort of a bounce detection algorithm. 如果您在谈论接收服务器上的错误,则需要实现VERP或某种形式的跳动检测算法。 PHPMailer-BMH may be useful in this case. 在这种情况下, PHPMailer-BMH可能有用。

My configuration uses sendmail and it outputs crash reports in the sendmail directory. 我的配置使用sendmail,并在sendmail目录中输出崩溃报告。 Check your folders for error dumps. 检查您的文件夹是否有错误转储。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM