Title: wp_mail_failed
Published: December 9, 2015
Last modified: February 24, 2026

---

# do_action( ‘wp_mail_failed’, WP_Error $error )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/hooks/wp_mail_failed/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/hooks/wp_mail_failed/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/wp_mail_failed/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/wp_mail_failed/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/wp_mail_failed/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/wp_mail_failed/?output_format=md#wp--skip-link--target)

Fires after a PHPMailer\PHPMailer\Exception is caught.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/wp_mail_failed/?output_format=md#parameters)󠁿

 `$error`[WP_Error](https://developer.wordpress.org/reference/classes/wp_error/)

A [WP_Error](https://developer.wordpress.org/reference/classes/wp_error/) object
with the PHPMailerPHPMailerException message, and an array containing the mail recipient,
subject, message, headers, and attachments.

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/wp_mail_failed/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/pluggable.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/pluggable.php#L661)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/pluggable.php#L661-L661)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/wp_mail_failed/?output_format=md#related)󠁿

| Used by | Description | 
| [wp_mail()](https://developer.wordpress.org/reference/functions/wp_mail/)`wp-includes/pluggable.php` |

Sends an email, similar to PHP’s mail function.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/wp_mail_failed/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/wp_mail_failed/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/wp_mail_failed/?output_format=md#comment-content-2051)
 2.   [Amid](https://profiles.wordpress.org/aminteractiondesign/)  [  9 years ago  ](https://developer.wordpress.org/reference/hooks/wp_mail_failed/#comment-2051)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_failed%2F%23comment-2051)
    Vote results for this note: 5[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_failed%2F%23comment-2051)
 4. Debugging [wp_mail()](https://developer.wordpress.org/reference/functions/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()](https://developer.wordpress.org/reference/functions/wp_mail/)
    error. But only use this for debugging.
 5.     ```php
        // show wp_mail() errors
        add_action( 'wp_mail_failed', 'onMailError', 10, 1 );
        function onMailError( $wp_error ) {
        	echo "<pre>";
            print_r($wp_error);
            echo "</pre>";
        }       
        ```
    
 6.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_failed%2F%3Freplytocom%3D2051%23feedback-editor-2051)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fwp_mail_failed%2F)
before being able to contribute a note or feedback.