Email & newsletters

Sending WordPress email through SMTP: why mail goes missing and how to fix it

Email & newsletters · · Published 2026-09-02 · Updated 2026-10-18

A red pillar postbox beside a stone wall and a red door
A red pillar box in a town square, waiting for the next collection.

Password resets that never arrive, contact-form notifications lost in spam: nearly all WordPress email problems have the same cause, and the same fix.

This address once hosted the ShiftThis "Swift SMTP" plugin, discontinued long ago and not available here. Its job, sending WordPress mail through an SMTP server, is now handled by several maintained plugins or by a few lines of code, both described below.

How WordPress sends email

Everything WordPress sends, from new-user notifications to WooCommerce receipts and form alerts, goes through one function: wp_mail(). Under the hood it uses the PHPMailer library, and by default PHPMailer hands the message to PHP's mail() function, which passes it to whatever mail program the web server has.

That default is the problem. The message leaves from a web server that was never meant to be a mail server. It is usually not covered by your domain's SPF record, it carries no DKIM signature for your domain, and on shared hosting the server's IP address is used by hundreds of other sites, some of which may send spam. Receiving providers see an unauthenticated message claiming to be from your domain and treat it accordingly: spam folder, or silent rejection. Some hosts disable mail() entirely, and then nothing is sent at all.

The fix: send through an authenticated server

Instead of mail(), have PHPMailer connect to a real SMTP server with a username and password (or an API key) and hand the message over there. That server is authorised for your domain, signs messages with DKIM, and has a sending reputation to protect. Options include:

Option 1: an SMTP plugin

For most sites a maintained plugin is the simplest route. WP Mail SMTP, FluentSMTP and Post SMTP are widely used examples in the official directory. They all do the same core job: replace the default transport with an SMTP connection or a provider's API, and add a test-email screen. Useful extras to look for are an email log (so you can see what was sent and whether it failed), a fallback connection, and native API integrations, which avoid problems with hosts that block outgoing SMTP ports.

Option 2: a few lines of code

If you prefer not to add a plugin, WordPress fires the phpmailer_init action just before sending, passing the PHPMailer object. A small must-use plugin (a PHP file in wp-content/mu-plugins/) can configure it:

<?php
// wp-content/mu-plugins/smtp.php
add_action( 'phpmailer_init', function ( $mailer ) {
    $mailer->isSMTP();
    $mailer->Host       = 'smtp.example.com';
    $mailer->Port       = 587;
    $mailer->SMTPSecure = 'tls';      // STARTTLS on port 587
    $mailer->SMTPAuth   = true;
    $mailer->Username   = SMTP_USER;  // defined in wp-config.php
    $mailer->Password   = SMTP_PASS;
} );

Define SMTP_USER and SMTP_PASS in wp-config.php (or as environment variables) rather than writing credentials into the plugin file, and never commit them to a public repository. Port 587 with STARTTLS is the usual submission port; port 465 uses implicit TLS (set SMTPSecure to 'ssl'). Port 25 is often blocked by hosts and should be avoided for submission.

Set the sender address correctly

By default WordPress sends from wordpress@yourdomain. Use an address on your own domain that your SMTP server is allowed to send for, set it in the plugin, or with the wp_mail_from and wp_mail_from_name filters:

add_filter( 'wp_mail_from', fn() => 'site@example.com' );
add_filter( 'wp_mail_from_name', fn() => 'Example Site' );

Contact-form plugins often let you put the visitor's address in the From field. Don't: your server is not authorised to send for their domain, so the message fails SPF and DMARC. Put the visitor's address in Reply-To instead.

Publish SPF, DKIM and DMARC

Switching transport only helps if your domain's DNS vouches for the new server:

Google's email sender guidelines explain why these records now matter for delivery to Gmail.

Test and monitor

  1. Send a test from the plugin's test screen, or trigger a password reset.
  2. In Gmail, open the message and choose Show original: SPF, DKIM and DMARC should each show PASS.
  3. If sending fails, enable the plugin's debug output or log. Typical errors are authentication failures (wrong credentials, or a provider that requires an app password or OAuth), connection timeouts (the host blocks the port; try 465, or use an API-based connection), and certificate errors (wrong hostname).
  4. Keep an email log for a few weeks to confirm that form notifications and receipts go out reliably.

Catching failures in code

wp_mail() returns false when PHPMailer cannot hand the message over, and WordPress fires the wp_mail_failed action with a WP_Error describing the problem. Logging it is a cheap safety net:

add_action( 'wp_mail_failed', function ( $error ) {
    error_log( 'wp_mail failed: ' . $error->get_error_message() );
} );

Note that true only means the server accepted the message, not that it reached the inbox; delivery problems after that point show up in your provider's logs or in DMARC reports.

Using a Google account as the server? Read WordPress and Gmail SMTP first: Google has changed its sign-in rules several times.

For a record-by-record walkthrough of the DNS side, including alignment and a safe DMARC rollout, see SPF, DKIM and DMARC for WordPress email.