有谁知道如何在php中捕获邮件错误(发送电子邮件时显示错误,该错误是由邮件服务器关闭引起的)?
由于电子邮件服务器关闭引起的错误如下:
这是你能做的最好的事情:
if (!mail(...)) {
// Reschedule for later try or panic appropriately!
}
http://php.net/manual/en/function.mail.php http://php.net/manual/en/function.mail.php
mail()
回报TRUE
如果邮件已成功接受投递,FALSE
否则。
请务必注意,邮件被接受投递并不意味着邮件实际上会到达预期目的地。
如果需要抑制警告,可以使用:
if (!@mail(...))
但使用时要小心@ http://www.php.net/manual/en/language.operators.errorcontrol.php操作员没有适当检查某件事是否成功。
If mail()
错误是不可抑制的(很奇怪,但现在无法测试),您可以:
a) 暂时关闭错误:
$errLevel = error_reporting(E_ALL ^ E_NOTICE); // suppress NOTICEs
mail(...);
error_reporting($errLevel); // restore old error levels
b)按照建议使用不同的邮件程序fire https://stackoverflow.com/questions/2323463/how-can-i-catch-an-error-caused-by-mail/2324857#2324857 and Mike https://stackoverflow.com/questions/2323463/how-can-i-catch-an-error-caused-by-mail/2323558#2323558.
If mail()
事实证明太脆弱和不灵活,我会研究b)。关闭错误会使调试变得更加困难,并且通常不好。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)