From bf5f3166689ae75927b3cb46a0db6f76834f361c Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Tue, 15 Sep 2015 23:50:30 +0000 Subject: [PATCH] Fire Action when mail exception is thrown. new action is wp_mail_failed which contains a WP_Error object with the phpmailerException code, message and an array with the mail information. Plugins can hook in and log when mails fail to send due to a phpmailer issue. Props soulseekah Fixes #18926 git-svn-id: https://develop.svn.wordpress.org/trunk@34221 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/pluggable.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index e54384671d..8e67accf3f 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -534,6 +534,18 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() try { return $phpmailer->Send(); } catch ( phpmailerException $e ) { + + $mail_error_data = compact( $to, $subject, $message, $headers, $attachments ); + /** + * Fires after a phpmailerException is caught + * + * @since 4.4.0 + * + * @param WP_Error A WP_Error object with the phpmailerException code, message and an array + * containing the mail recipient, subject, message, headers and attachments + */ + do_action( 'wp_mail_failed', new WP_Error( $e->getCode(), $e->getMessage(), $mail_error_data ) ); + return false; } }