Skip to content

WordPress mail logging — what to log and how to query it

A WordPress site that does not log outbound mail cannot triage delivery failures. Here is what to log, where to put it, and the queries you actually need at 2am.

A customer says “I didn’t get the password reset.” The WordPress admin opens wp-admin > Tools > Email Log and sees… nothing. No plugin is logging, no wp_mail_failed handler is wired up, no SMTP plugin log is enabled. The triage is now guesswork. Email logging is not glamorous, but on a site that has any kind of user-facing mail flow, it is the single largest improvement to support-ticket triage time you can make.

What’s happening

WordPress core does not log wp_mail() calls. The plugin layer does it — three patterns:

  1. SMTP-plugin logs. WP Mail SMTP, FluentSMTP, and Post SMTP all ship an email log feature. Captures every wp_mail call with subject, recipient, status, and (in Pro tiers or always in FluentSMTP) the body. Lives in a custom DB table.
  2. Standalone log plugins. WP Mail Logging (free, .org), and a few others, capture the same data but work even if your SMTP plugin’s log is gated behind a paywall.
  3. Application logs. Drop your own logger via wp_mail_succeeded and wp_mail_failed actions, writing structured JSON to a file or shipping to a log aggregator.

The pattern that matters in production is option 3 stacked on option 1: SMTP plugin captures the body for in-context replay; structured JSON ships to your log aggregator (Datadog, Loki, ELK) for cross-site queries. The DB-only approach falls apart at fleet scale — querying email logs across 50 sites means 50 SQL queries.

How to verify

If you’re on WP Mail SMTP or FluentSMTP with logs enabled:

wp db query "SELECT id,subject,to_email,status,created_at FROM wp_wpmailsmtp_email_log ORDER BY id DESC LIMIT 20"
wp db query "SELECT id,subject,email_to,status,created_at FROM wp_fsmtp_email_log ORDER BY id DESC LIMIT 20"

Table names vary by plugin and version — check SHOW TABLES LIKE '%mail%' if neither matches.

For a fleet-wide view, check that the log shipper is running:

journalctl -u rsyslog -n 50 | grep wp-mail
ls -lh /var/log/wp-mail/example.com/$(date +%Y%m%d).log

The fix

  1. Pick the SMTP plugin’s email log as the primary capture. Enable it with a 30-day retention. The retention matters — too short and you lose triage signal; too long and the table grows unbounded and starts costing storage and slow admin pages.

  2. Wire structured logging to a file via wp_mail_succeeded and wp_mail_failed. Drop a mu-plugin:

    <?php
    add_action('wp_mail_succeeded', function($mail_data) {
        $log = [
            'ts' => current_time('c'),
            'site' => home_url(),
            'to' => $mail_data['to'],
            'subject' => $mail_data['subject'],
            'status' => 'sent',
        ];
        error_log(json_encode($log) . "\n", 3, WP_CONTENT_DIR . '/logs/wp-mail.json.log');
    });
    
    add_action('wp_mail_failed', function($error) {
        $log = [
            'ts' => current_time('c'),
            'site' => home_url(),
            'status' => 'failed',
            'error' => $error->get_error_message(),
            'data' => $error->get_error_data(),
        ];
        error_log(json_encode($log) . "\n", 3, WP_CONTENT_DIR . '/logs/wp-mail.json.log');
    });
  3. Ship the JSON log to your aggregator. Promtail to Loki, Vector to Elasticsearch, fluent-bit to Datadog — whichever stack you run. Set the log shipper to tail wp-content/logs/wp-mail.json.log and apply the site and status labels.

  4. Build the queries you actually need.

    • “Failed sends in the last 24 hours, by site” — status=failed, group by site.
    • “Sends to a specific user across all sites” — to=user@example.com.
    • “Sends matching subject (for a specific notification class)” — subject:"Password reset*".
  5. Set an alert on failure rate. A WordPress site that suddenly starts failing 30% of its wp_mail() calls is the kind of incident you want to know about in 5 minutes, not when a customer complains.

  6. Audit the log table size monthly. A plugin that logs the full body of every send can balloon wp_options autoload or grow a custom table by GBs. The retention setting is what keeps this bounded. On enterprise WordPress hosting deployments, the audit is part of the monthly drift report.

Stack Harbor wires structured email logging into every enterprise WordPress hosting deployment with the cross-site dashboard pre-built. If you currently rely on individually logging into each site to triage email delivery, the consolidation is part of the engagement.