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

wp-config.php

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

wp-content/themes/<your_theme>/functions.php

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->isSMTP();
	$phpmailer->Host = 'smtp.office365.com';
	$phpmailer->SMTPAuth = true;
	$phpmailer->Username = 'user@host.se';
	$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 = 'user@host.se';
	$phpmailer->FromName = 'ASBRA ISP';
}
add_action( 'phpmailer_init', 'ab_phpmailer' );