# Check the SMTP Connection Without Sending

> Adds Tools > SMTP Check, which connects and logs in to your configured SMTP server and reports success or the exact error, without sending an email to anyone.

- Type: PHP
- Runs: Admin only
- Category: [Email](https://wpide.com/library/category/email/)
- Tags: email, smtp, admin
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/email-smtp-connection-check/

## Code

```php
add_action( 'admin_menu', function () {
    add_management_page( 'SMTP Check', 'SMTP Check', 'manage_options', 'wpide-smtp-check', function () {
        echo '<div class="wrap"><h1>SMTP Check</h1>';

        if ( isset( $_POST['wpide_smtp_check'] ) && check_admin_referer( 'wpide_smtp_check' ) && current_user_can( 'manage_options' ) ) {
            require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
            require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
            require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';

            $mailer = new PHPMailer\PHPMailer\PHPMailer( true );
            $mailer->Timeout = 10;
            do_action_ref_array( 'phpmailer_init', array( &$mailer ) );

            if ( 'smtp' !== $mailer->Mailer ) {
                echo '<div class="notice notice-warning"><p>WordPress is not configured to use SMTP. Emails are sent with PHP mail().</p></div>';
            } else {
                try {
                    $ok = $mailer->smtpConnect();
                    $mailer->smtpClose();
                    printf( '<div class="notice notice-%1$s"><p>%2$s</p></div>', $ok ? 'success' : 'error', esc_html( $ok ? sprintf( 'Connected and authenticated with %s:%d.', $mailer->Host, $mailer->Port ) : 'Could not connect: ' . $mailer->ErrorInfo ) );
                } catch ( Exception $e ) {
                    printf( '<div class="notice notice-error"><p>%s</p></div>', esc_html( 'Could not connect: ' . $e->getMessage() ) );
                }
            }
        }

        echo '<p>Connects to the SMTP server with your current settings and logs in, without sending anything.</p><form method="post">';
        wp_nonce_field( 'wpide_smtp_check' );
        echo '<button class="button button-primary" name="wpide_smtp_check" value="1">Run the check</button></form></div>';
    } );
} );
```

## Notes

Uses whatever SMTP settings your other snippets or mail plugin apply through phpmailer_init; if nothing switches WordPress to SMTP, it tells you so.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Check the SMTP Connection Without Sending" 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/
