# 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.

- Type: PHP
- Runs: Run everywhere
- Category: [Email](https://wpide.com/library/category/email/)
- Tags: email, smtp, debugging
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/email-smtp-debug-log/

## Code

```php
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 use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Write SMTP Conversation to the Debug Log" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
