Skip to content

Instantly share code, notes, and snippets.

@Bobz-zg
Last active November 13, 2022 15:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Bobz-zg/118ea5867ff33672c91493e79b356f88 to your computer and use it in GitHub Desktop.
Save Bobz-zg/118ea5867ff33672c91493e79b356f88 to your computer and use it in GitHub Desktop.
Debug wp_mail function. Display errors on screen
<?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