Write SMTP Conversation to the Debug Log
Records the conversation between WordPress and your SMTP server in the PHP error log while you troubleshoot, with passwords and login tokens blanked out.
Opens WPIDE on
Code
add_action( 'phpmailer_init', function ( $phpmailer ) {
if ( ! defined( 'WPIDE_SMTP_DEBUG' ) || ! WPIDE_SMTP_DEBUG ) {
return;
}
$phpmailer->SMTPDebug = 2;
$phpmailer->Debugoutput = function ( $text ) {
$text = trim( (string) $text );
// Hide credentials: AUTH arguments and base64 lines sent by the client.
$text = preg_replace( '/^(CLIENT -> SERVER:\s*AUTH\s+\S+)\s+.+$/i', '$1 [redacted]', $text );
if ( preg_match( '/^CLIENT -> SERVER:\s*(\S+)\s*$/', $text, $m ) && preg_match( '/^[A-Za-z0-9+\/=]{8,}$/', $m[1] ) && ! preg_match( '/^(EHLO|HELO|QUIT|DATA|RSET|NOOP|STARTTLS)$/i', $m[1] ) ) {
$text = 'CLIENT -> SERVER: [redacted]';
}
error_log( 'SMTP: ' . $text );
};
}, 1000 );
Notes
Only runs while WPIDE_SMTP_DEBUG is defined as true in wp-config.php; turn it off when you are done because the log grows quickly.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.