Skip to content

Instantly share code, notes, and snippets.

@ionurboz
Forked from Bobz-zg/debug-wpmail.php
Created November 13, 2022 15:02
Show Gist options
  • Save ionurboz/288bff17e50bbdd464bb9589787614b5 to your computer and use it in GitHub Desktop.
Save ionurboz/288bff17e50bbdd464bb9589787614b5 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