Debugging PHP-Mailer in WordPress

Handle the lack of information about errors in the wordpress phpmailer implementation

Start by activating and redirecting all of your debugging info to the apache error.log


define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);


error_log('Testing WP error logging!');

function hook_wp_mail_failed($wp_error)
    return error_log(print_r($wp_error, true));

add_action('wp_mail_failed', 'hook_wp_mail_failed', 10, 1);

Using SMTP with authentication from a plugin

Redirect all your mail traffic to SMTP-Auth. Start by scaffolding yourself a new plugin:

# wp scaffold plugin --plugin_name=ab-smtp-auth
function ab_phpmailer( $phpmailer )
	$phpmailer->Host = '';
	$phpmailer->SMTPAuth = true;
	$phpmailer->Username = '';
	$phpmailer->Password = 'pa$$word';
	$phpmailer->Port = 587;
	$phpmailer->SMTPSecure = "tls"; // Choose 'ssl' for SMTPS on port 465, or 'tls' for SMTP+STARTTLS on port 25 or 587
	$phpmailer->From = '';
	$phpmailer->FromName = 'ASBRA ISP';
add_action( 'phpmailer_init', 'ab_phpmailer' );