# Send a Test Email From the Admin

> Adds a Tools > Send Test Email screen where administrators can send a test message to any address and see right away whether WordPress could hand it off.

- Type: PHP
- Runs: Run everywhere
- Category: [Email](https://wpide.com/library/category/email/)
- Tags: email, testing, deliverability, admin
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/email-test-tool/

## Code

```php
add_action( 'admin_menu', function () {
    add_management_page( 'Send Test Email', 'Send Test Email', 'manage_options', 'wpide-test-email', function () {
        $result = null;
        $error  = '';

        if ( isset( $_POST['wpide_test_email'] ) && check_admin_referer( 'wpide_test_email' ) && current_user_can( 'manage_options' ) ) {
            $to = sanitize_email( wp_unslash( $_POST['wpide_test_email'] ) );

            if ( is_email( $to ) ) {
                $capture = function ( $wp_error ) use ( &$error ) {
                    $error = $wp_error->get_error_message();
                };
                add_action( 'wp_mail_failed', $capture );
                $result = wp_mail( $to, 'Test email from ' . wp_specialchars_decode( get_bloginfo( 'name' ), ENT_QUOTES ), "This is a test email sent from " . home_url() . " at " . wp_date( 'Y-m-d H:i:s' ) . '.' );
                remove_action( 'wp_mail_failed', $capture );
            } else {
                $error = 'Please enter a valid email address.';
            }
        }

        echo '<div class="wrap"><h1>Send Test Email</h1>';

        if ( true === $result ) {
            echo '<div class="notice notice-success"><p>The email was handed to the mail server.</p></div>';
        } elseif ( false === $result || $error ) {
            echo '<div class="notice notice-error"><p>' . esc_html( $error ? $error : 'The email could not be sent.' ) . '</p></div>';
        }

        echo '<form method="post">';
        wp_nonce_field( 'wpide_test_email' );
        printf( '<p><label for="wpide_test_email">Send to</label><br><input type="email" class="regular-text" id="wpide_test_email" name="wpide_test_email" value="%s" required></p>', esc_attr( wp_get_current_user()->user_email ) );
        submit_button( 'Send test email' );
        echo '</form></div>';
    } );
} );
```

## Notes

A "sent" result means the mail server accepted it; check spam folders if it does not arrive.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Send a Test Email From the Admin" 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/
