Although wp_mail
returns false on failure, it does also contain an action hook to allow you access to error information.
If phpmailer
fails to send, these lines run:
/**
* Fires after a phpmailerException is caught.
*
* @since 4.4.0
*
* @param WP_Error $error A WP_Error object with the phpmailerException message, and an array
* containing the mail recipient, subject, message, headers, and attachments.
*/
do_action( 'wp_mail_failed', new WP_Error( 'wp_mail_failed', $e->getMessage(), $mail_error_data ) );
return false;
If you attach a function to wp_mail_failed
you can look at the WP_Error
object to get more info on your problem.