# Email Delivery Check in Site Health

> Adds a test to Tools > Site Health that warns when WordPress sends mail with plain PHP mail() instead of SMTP or an API, and when an email has failed recently.

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

## Code

```php
add_action( 'wp_mail_failed', function ( $error ) {
    update_option( 'wpide_mail_last_failure', array( 'time' => time(), 'message' => $error->get_error_message() ), false );
} );

add_filter( 'site_status_tests', function ( $tests ) {
    $tests['direct']['wpide_mail'] = array(
        'label' => 'Email delivery',
        'test'  => function () {
            require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
            $mailer = new PHPMailer\PHPMailer\PHPMailer( true );
            do_action_ref_array( 'phpmailer_init', array( &$mailer ) );

            $api     = has_filter( 'pre_wp_mail' ) > 0;
            $failure = get_option( 'wpide_mail_last_failure' );
            $recent  = is_array( $failure ) && $failure['time'] > time() - WEEK_IN_SECONDS;

            $result = array(
                'label'       => 'Email is sent through SMTP or an email service',
                'status'      => 'good',
                'badge'       => array( 'label' => 'Email', 'color' => 'blue' ),
                'description' => '<p>WordPress emails go through a dedicated mail server, which is the most reliable setup.</p>',
                'actions'     => '',
                'test'        => 'wpide_mail',
            );

            if ( 'smtp' !== $mailer->Mailer && ! $api ) {
                $result['status']      = 'recommended';
                $result['label']       = 'Email is sent with PHP mail()';
                $result['description'] = '<p>Emails sent with PHP mail() often land in spam or are blocked. Configure SMTP or an email API for reliable delivery.</p>';
            }

            if ( $recent ) {
                $result['status']       = 'critical';
                $result['label']        = 'An email failed to send recently';
                $result['description'] .= '<p>Last failure: ' . esc_html( wp_date( 'Y-m-d H:i', $failure['time'] ) . ' – ' . $failure['message'] ) . '</p>';
            }

            return $result;
        },
    );

    return $tests;
} );
```

## Notes

Failures are recorded from the moment the snippet is active; the warning clears seven days after the last failure.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Email Delivery Check in Site Health" 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/
