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

问题描述

我似乎使用PHP的邮件发送电子邮件()。我也曾尝试PHPMailer的和Swiftmail没有成功。但是,服务器上运行以下命令成功地将邮件传递。

I cant seem to send an email using PHP's mail(). I have also tried PHPMailer and Swiftmail with no success. However, the following command on the server delivers mail successfully.

cat test.txt | mail -s "test mail" [email protected]

有没有办法追查问题出在哪里是哪里来的?邮件()似乎只是返回true或false。

Is there a way to trace where the problem is coming from? mail() just seems to return true or false.

推荐答案

在PHP> = 5.2,有中检索任何错误是由最后一个函数调用返回。有一个关于如何从链接的页面在旧版本的PHP相当于详细信息。

On PHP >= 5.2, there's error_get_last() to retreive whatever error was returned by the last function call. There's details on how to get equivalent information from older versions of PHP on the linked page.

至于PHPMailer的,还有的 $ mailer->包含一个错误ERRORINFO 属性发生。 SwiftMailer必须有类似的东西。如果在命令行中邮件的工作,但没有从内部PHP或邮件库,有一个在玩一个错误配置的可能性最大。我猜你的主机不具备PHP sendmail_path 的ini配置参数。

As for PHPMailer, there's the $mailer->ErrorInfo property which contains the last error occured. SwiftMailer must have something similar. Most likely if mail's working from the command line but not from within PHP or the mailing libraries, there's a misconfiguration at play. I'm guessing your host doesn't have the PHP sendmail_path ini parameter configured.

这篇关于sendmail的工作,但PHP邮件()失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 18:05