问题描述
有没有人知道如何捕获邮件错误(错误显示,同时发现电子邮件,错误是由邮件服务器导致的)php?
Does anyone know how can I catch mail error (error display while sening email and the error is caused by the mailserver down) in php?
电子邮件服务器如下:
推荐答案
这是关于你最好的做法:
This is about the best you can do:
if (!mail(...)) {
// Reschedule for later try or panic appropriately!
}
重要的是要注意,只是因为邮件被接受送达,这并不意味着邮件将实际到达目的地。
It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
如果您需要禁止警告,可以使用:
If you need to suppress warnings, you can use:
if (!@mail(...))
请注意,使用操作员,无需检查某些成功与否。
Be careful though about using the @
operator without appropriate checks as to whether something succeed or not.
如果 mail()
错误不可抑制(奇怪,但可以'现在可以测试),您可以:
If mail()
errors are not suppressible (weird, but can't test it right now), you could:
a)暂时关闭错误:
$errLevel = error_reporting(E_ALL ^ E_NOTICE); // suppress NOTICEs
mail(...);
error_reporting($errLevel); // restore old error levels
b)使用不同的邮件程序,如和。
b) use a different mailer, as suggested by fire and Mike.
如果 mail()
证明是太片面和僵化,我会看看b)。关闭错误是使调试更加困难,而且通常是不好的。
If mail()
turns out to be too flaky and inflexible, I'd look into b). Turning off errors is making debugging harder and is generally ungood.
这篇关于如何捕获由mail()引起的错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!