do_action( ‘wp_mail_failed’, WP_Error $error )

Fires after a PHPMailer\PHPMailer\Exception is caught.

Parameters

$errorWP_Error
A WP_Error object with the PHPMailerPHPMailerException message, and an array containing the mail recipient, subject, message, headers, and attachments.

Source

do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_data ) );

Changelog

VersionDescription
4.4.0Introduced.

User Contributed Notes

  1. Skip to note 2 content

    Debugging wp_mail() can be a lot easier with this simple method.
    It will display a more helpful error message (the original phpmailer error) than WordPress will by default.
    Just add this function to display the real wp_mail() error.
    But only use this for debugging.

    // show wp_mail() errors
    add_action( 'wp_mail_failed', 'onMailError', 10, 1 );
    function onMailError( $wp_error ) {
    	echo "<pre>";
        print_r($wp_error);
        echo "</pre>";
    }       

You must log in before being able to contribute a note or feedback.