Title: wp_mail_failed Hook
Last modified: December 14, 2016

---

# wp_mail_failed Hook

 *  Resolved [jfgrenier](https://wordpress.org/support/users/jfgrenier/)
 * (@jfgrenier)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/wp_mail_failed-hook/)
 * Wordpress introduced since version 4.4.0 the **wp_mail_failed** hook after a 
   phpmailerException is caught. Can you add this Hook at the end of the wp_mail
   function in main.php ?
 * Also, on our end, we need the defaut catch exception in case some Gmail credentials
   have been removed from WP or Gmail account, or if the mail can’t be send in any
   way.
 * Here’s how we edited the try&catch at the end of main.php
 *     ```
       try {
       		return $phpmailer->Send();
       	} catch ( phpmailerException $e ) {
       		$mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
        		do_action( 'wp_mail_failed', new WP_Error( $e->getCode(), $e->getMessage(), $mail_error_data ) );
       		return false;
       	}
       	catch ( Exception $e ) {
       		$mail_error_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
        		do_action( 'wp_mail_failed', new WP_Error( $e->getCode(), $e->getMessage(), $mail_error_data ) );
       		return false;
       	}
       ```
   
 * Thanks

Viewing 1 replies (of 1 total)

 *  Plugin Author [Noor Alam](https://wordpress.org/support/users/naa986/)
 * (@naa986)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/wp_mail_failed-hook/#post-8583541)
 * Hi, Thank you for the feedback. I have just updated it in the plugin.

Viewing 1 replies (of 1 total)

The topic ‘wp_mail_failed Hook’ is closed to new replies.

 * ![](https://ps.w.org/gmail-smtp/assets/icon-128x128.png?rev=2432932)
 * [Gmail SMTP](https://wordpress.org/plugins/gmail-smtp/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gmail-smtp/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gmail-smtp/)
 * [Active Topics](https://wordpress.org/support/plugin/gmail-smtp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gmail-smtp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gmail-smtp/reviews/)

## Tags

 * [gmail](https://wordpress.org/support/topic-tag/gmail/)
 * [phpmailer](https://wordpress.org/support/topic-tag/phpmailer/)

 * 1 reply
 * 2 participants
 * Last reply from: [Noor Alam](https://wordpress.org/support/users/naa986/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/wp_mail_failed-hook/#post-8583541)
 * Status: resolved