How can I catch an error caused by mail()?

后端 未结 5 759
陌清茗
陌清茗 2020-12-01 18:06

Does anyone know how can I catch a mail error (error is displayed while sending email and the error is caused by the mailserver down) in php?

Error that was caused b

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 18:24

    You could use the PEAR Mail classes and methods, which allows you to check for errors via:

    if (PEAR::isError($mail)) {
        echo("

    " . $mail->getMessage() . "

    "); } else { echo("

    Message successfully sent!

    "); }

    You can find an example here.

提交回复
热议问题