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

Password resets that never arrive, contact-form notifications lost in spam: nearly all WordPress email problems have the same cause, and the same fix.
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:
- The mailbox you already have: the SMTP server of your email host, Microsoft 365, or Google Workspace. Fine for low volumes such as notifications and password resets, within the provider's sending limits.
- A transactional email service such as Amazon SES, Postmark, Mailgun, SendGrid or Brevo. These are built for application email, give you delivery logs, and handle bounces. Most have a free or low-cost tier for small volumes.
- Your host's own relay, if it offers an authenticated one.
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:
- Add the provider to your single SPF TXT record (for example with the
include:value it documents). - Publish the DKIM record or records the provider gives you, and verify the domain in its dashboard.
- Publish a DMARC record;
v=DMARC1; p=none; rua=mailto:reports@example.comis a safe start that only collects reports.
Google's email sender guidelines explain why these records now matter for delivery to Gmail.
Test and monitor
- Send a test from the plugin's test screen, or trigger a password reset.
- In Gmail, open the message and choose Show original: SPF, DKIM and DMARC should each show
PASS. - 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).
- 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.
Email & newslettersWordPress and Gmail SMTP
How to send WordPress email through a Gmail or Google Workspace account today: server settings, app passwords, OAuth, the Workspace SMTP relay, limits and pitfalls.
Email & newslettersSending a newsletter
How to run an email newsletter from a WordPress site today: in-site plugins versus email services, double opt-in, unsubscribe rules, and sender authentication.
Logins & site adminLogin lockouts and maintenance mode
Two kinds of lock-out for WordPress: limiting failed login attempts against brute-force attacks, and closing the site to visitors during maintenance without hurting SEO.