且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何捕获由mail()引起的错误?

更新时间:2022-12-03 09:23:54

这是关于你***的做法:

This is about the best you can do:

if (!mail(...)) {
   // Reschedule for later try or panic appropriately!
}

http://php.net/manual/en/function.mail.php


mail()返回 TRUE 如果邮件成功接受送达, FALSE 否则

mail() returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

重要的是要注意,只是因为邮件被接受送达,这并不意味着邮件将实际到达目的地。

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)使用不同的邮件程序,如 fire Mike

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.