Last active
November 13, 2022 15:02
-
-
Save Bobz-zg/118ea5867ff33672c91493e79b356f88 to your computer and use it in GitHub Desktop.
Debug wp_mail function. Display errors on screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Display errors | |
*/ | |
if ( ! function_exists('debug_wpmail') ) : | |
function debug_wpmail( $result = false ) { | |
if ( $result ) | |
return; | |
global $ts_mail_errors, $phpmailer; | |
if ( ! isset($ts_mail_errors) ) | |
$ts_mail_errors = array(); | |
if ( isset($phpmailer) ) | |
$ts_mail_errors[] = $phpmailer->ErrorInfo; | |
print_r('<pre>'); | |
print_r($ts_mail_errors); | |
print_r('</pre>'); | |
} | |
endif; | |
/** | |
* Usage | |
*/ | |
$res = wp_mail($to, $subject, $message); | |
debug_wpmail($res); // Will print_r array of errors |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment