This page configures one plugin: WP Mail SMTP. It covers the whole install-to-working path — activate it, pick a mailer, connect and authenticate that mailer, move the credentials into wp-config.php, send a test that prints the real error instead of a green checkmark, and diagnose the send when it fails. If you have not settled on this plugin yet and are still weighing it against FluentSMTP, Post SMTP or Easy WP SMTP, start with WordPress SMTP plugins compared and come back here once WP Mail SMTP is the decision.
What the plugin does is narrower than most people expect. It replaces the PHP mail() call behind wp_mail() with an authenticated connection to a mail service that already has sending reputation; it does not make receivers accept the message. SPF, DKIM and DMARC alignment on the sending domain decides that, and no combination of plugin settings substitutes for a correct DNS record. So the guide covers both halves of a working install — the configuration, and the verification that proves the mail arrived rather than merely left. On a healthy host the configuration is about fifteen minutes; the verification is the part worth doing slowly.
What you’ll accomplish
- WordPress sending through an authenticated relay instead of the local MTA, with the reason the local MTA failed understood rather than guessed at.
- A WP Mail SMTP mailer chosen against a measured fact — whether outbound SMTP ports are open — rather than against the host’s documentation.
- The right port and encryption pairing for that mailer, and the OAuth or API-key exchange completed for the mailers that need one.
- Credentials defined as
WPMS_constants inwp-config.php, so they never enterwp_optionsand never appear in a database export handed to a contractor. - A From address that survives DMARC, with the Return-Path and DKIM signature that make it survive.
- A command-line verification loop and a log-reading habit that turn a failed send into a message rather than a shrug.
Prerequisites
- WordPress 5.9 or newer on PHP 7.4 or newer. WP Mail SMTP runs on older versions, but the settings layout described here is the one shipped with the 3.x and 4.x releases.
- Administrator access to WordPress, plus SFTP or SSH to edit
wp-config.php. The constants half of this guide is not possible from wp-admin alone. - WP-CLI on the server for the verification steps. Every check below has a wp-admin equivalent, but the plugin’s own test screen hides the error text you need, which is exactly why the CLI is worth the trouble.
- DNS control for the sending domain. If you cannot publish a TXT record, stop here and get that first — the rest is decoration without it.
- A mail service account: your host’s mailbox credentials, a transactional provider, or a Google Workspace or Microsoft 365 tenant.
- Assume nothing about outbound ports. Many shared and cPanel hosts block outbound 25, 465 and 587 to everything except their own relay; step 2 tests this rather than trusting the host’s documentation.
How it works
wp_mail() is a pluggable function. In a default install it builds a PHPMailer object, sets isMail(), and hands the message to PHP’s mail(), which shells out to sendmail on the local machine. The message leaves from the web server’s own IP with a From address of wordpress@yourhostname. Receivers see an unknown IP sending on behalf of a domain whose SPF record does not list it, and the message is silently dropped or filed as spam. Nothing errors. wp_mail() returns true, because handing the message to sendmail succeeded.
WP Mail SMTP hooks phpmailer_init and reconfigures that same PHPMailer object before it sends: either isSMTP() with a host, port, encryption mode and credentials, or — for the API mailers — it bypasses PHPMailer’s transport entirely and posts the message to the provider’s HTTP endpoint. The second path matters more than it sounds, because an HTTPS POST on port 443 works on hosts where every SMTP port is firewalled outbound.
At the receiving end, three checks run and only the third decides the outcome. SPF asks whether the connecting IP is authorised for the envelope sender — the Return-Path, not the visible From. DKIM verifies a cryptographic signature against a public key published at <selector>._domainkey.<domain>. DMARC then requires that at least one of those passed and that the domain it passed for aligns with the domain in the visible From header. That last clause is the trap: a relay can pass SPF for its own bounce domain and pass DKIM for its own signing domain, and the message still fails DMARC because neither matches your From. Configuring the provider to sign as your domain — the step every provider calls “domain authentication” or “sender verification” — is what fixes it, and it happens in DNS, not in WordPress.
Which mailer you select inside WP Mail SMTP changes how much of that you arrange yourself, and the first fork is not a preference but a firewall test.
Step-by-step
-
Install the plugin and confirm nothing else is filtering mail. Two plugins reconfiguring PHPMailer will fight, and the loser is whichever hooks first.
wp plugin install wp-mail-smtp --activate wp plugin list --status=active --field=name | grep -iE 'smtp|mail|postman'Expected output:
wp-mail-smtpand nothing else mail-related. If FluentSMTP, Post SMTP, Easy WP SMTP or an old Postman Mailer appears, deactivate it before continuing. A stacked mailer is the single most common cause of “I configured it and it still sends from the wrong address”. -
Test the outbound ports before you pick a mailer. This is the fork in the decision tree above, and it takes ten seconds.
timeout 5 bash -c 'cat < /dev/null > /dev/tcp/smtp.example.net/587' && echo "587 open" || echo "587 blocked" timeout 5 bash -c 'cat < /dev/null > /dev/tcp/smtp.example.net/465' && echo "465 open" || echo "465 blocked"Expected output:
587 open. If both report blocked, an SMTP mailer cannot work from this server no matter what credentials you supply, and you need an API-based mailer or a host firewall change. On cPanel and WHM servers, check whether “Restrict outgoing SMTP” is enabled in Tweak Settings — it forces all outbound mail through the local Exim regardless of what the plugin is configured to do. -
Verify the relay actually speaks TLS on that port. An open port is not a working relay.
openssl s_client -starttls smtp -crlf -connect smtp.example.net:587Expected output: a certificate chain, then a
250capability list including250-STARTTLSand250-AUTH PLAIN LOGIN. TypeQUITto exit. If the certificate CN does not match the hostname you connected to, fix the hostname now rather than turning off verification later. -
Run the setup wizard once, then throw away what it stored. Activating the plugin launches a wizard. Walk it through with the mailer you chose so it writes the non-secret structure — mailer type, From name, Return-Path preference — then move the secrets out in the next step. Setting the From address to a real mailbox on the sending domain is the part people skip:
notifications@example.comis correct,wordpress@srv412.hostingco.netis the default that guarantees a DMARC failure. -
Move every credential into
wp-config.php.WPMS_ONis the master switch; without it the plugin ignores the rest. Add this block above the/* That's all, stop editing! */line:define( 'WPMS_ON', true ); define( 'WPMS_MAILER', 'smtp' ); define( 'WPMS_MAIL_FROM', 'notifications@example.com' ); define( 'WPMS_MAIL_FROM_FORCE', true ); define( 'WPMS_MAIL_FROM_NAME', 'Example Store' ); define( 'WPMS_MAIL_FROM_NAME_FORCE', true ); define( 'WPMS_SET_RETURN_PATH', true ); define( 'WPMS_SMTP_HOST', 'smtp.example.net' ); define( 'WPMS_SMTP_PORT', 587 ); define( 'WPMS_SSL', 'tls' ); define( 'WPMS_SMTP_AUTH', true ); define( 'WPMS_SMTP_USER', 'notifications@example.com' ); define( 'WPMS_SMTP_PASS', 'the-application-password' );The two
_FORCEconstants make the plugin overwrite the From values that plugins like WooCommerce and Contact Form 7 set on their own; without them a plugin’s own From address wins and DMARC fails for that message class only, which is a miserable bug to chase. -
Confirm the constants took effect. Reload WP Mail SMTP > Settings in wp-admin: every field you defined should now be greyed out with a note that it is set by a constant. From the CLI:
wp eval 'echo ( defined( "WPMS_ON" ) && WPMS_ON ) ? "constants active" : "NOT active";'Expected output:
constants active. If it printsNOT active, the block landed below thestop editingline or in the wrongwp-config.php— some stacks keep one a directory above the web root. -
Purge the credentials the wizard already wrote to the database. Constants take precedence at runtime, but the old values stay in
wp_optionsuntil you look at them.wp option get wp_mail_smtp --format=jsonExpected output: a JSON blob. Read the
smtpand any provider sections. If a password or API key is sitting in there in plain text, clear that field in the settings UI and re-run the command until it comes back empty. Anything left behind ships with every database dump you hand to a developer or a migration tool.wp config set WPMS_SMTP_PASS 'the-application-password'wp config setis the scriptable way to add these, but it puts the secret in your shell history — rununset HISTFILEfirst, or edit the file directly.
Ports, encryption and the per-mailer constants
Three of the settings in step 5 have to agree with each other, and a mismatch produces a timeout rather than a useful error. Port 587 is the submission port and expects STARTTLS: the session opens in clear text and is upgraded by the STARTTLS command, which is WPMS_SSL set to 'tls'. Port 465 is implicit TLS — the handshake happens before any SMTP verb — which is WPMS_SSL set to 'ssl'. Port 25 is server-to-server relay, not submission; it is blocked on most networks and should not appear in a WordPress configuration. Setting WPMS_SSL to '' disables encryption and sends the password in the clear, so treat it as a diagnostic step you undo, never a configuration you keep. WPMS_SMTP_AUTOTLS controls whether PHPMailer opportunistically upgrades a plain session when the server advertises STARTTLS; leave it on unless a broken relay makes the handshake fail, and if you find yourself turning it off, fix the relay instead.
The API mailers replace the whole WPMS_SMTP_* block with a provider-specific set, and WPMS_MAILER names which one is active. 'smtp' and 'mail' are the two transport-level values; 'mailgun', 'sendgrid', 'gmail' and 'outlook' are among the provider values. Mailgun reads WPMS_MAILGUN_API_KEY, WPMS_MAILGUN_DOMAIN and WPMS_MAILGUN_REGION — the region constant is the one people miss, and an EU-region account configured without it fails authentication against the US endpoint with a confusing message. SendGrid reads WPMS_SENDGRID_API_KEY. The Gmail and Outlook mailers read WPMS_GMAIL_CLIENT_ID and WPMS_GMAIL_CLIENT_SECRET, and WPMS_OUTLOOK_CLIENT_ID and WPMS_OUTLOOK_CLIENT_SECRET respectively, and they still require you to click through the consent screen once in wp-admin: the constants carry the application identity, but the refresh token is issued by the authorisation round trip and is stored by the plugin. That token is also what expires. A workspace password change, an admin consent policy, or ninety days of inactivity on an unverified app will revoke it, and mail stops weeks after a setup that tested perfectly.
Guessing a constant name silently does nothing — the plugin simply does not see it, and the settings screen keeps showing an editable field. The plugin’s documentation lists the exact constant for every mailer, so check it rather than inferring the pattern.
Validate it works
The plugin’s Email Test tab reports success when PHPMailer accepts the message. That is not the same as delivery, and it is why sites “test fine” and still lose receipts. Verify at three levels instead.
First, get the real error text. wp_mail() returns a bare boolean, but it fires wp_mail_failed with a WP_Error carrying the PHPMailer exception:
wp eval '
add_action( "wp_mail_failed", function ( $error ) {
echo "FAILED: " . $error->get_error_message() . PHP_EOL;
} );
var_dump( wp_mail( "you@example.com", "wp-mail-smtp check", "body" ) );
'
Expected output: bool(true) and no FAILED: line. A FAILED: line gives you the SMTP response code — 535, 550, 421 — which is the thing you actually search for.
Second, confirm the DNS half is in place before you blame the plugin:
dig +short TXT example.com | grep -i spf
dig +short TXT _dmarc.example.com
dig +short TXT s1._domainkey.example.com
Expected output: one v=spf1 record and exactly one, a v=DMARC1 record, and a key at whatever selector your provider told you to publish. Two SPF records is a permanent error, not a warning — receivers treat it as permerror and SPF fails outright. The mechanics of each record are covered in transactional mail DNS verification.
Third, read the headers of a message that actually arrived. Send to a mailbox you control, open the raw source, and find the Authentication-Results header:
Authentication-Results: mx.example.org;
spf=pass smtp.mailfrom=example.com;
dkim=pass header.d=example.com;
dmarc=pass header.from=example.com
The domains after smtp.mailfrom, header.d and header.from must match. If dkim=pass header.d= shows the provider’s domain rather than yours, DKIM is passing but not aligning — finish the provider’s domain authentication step. Finally, trigger a real send through the path your users take, not a synthetic one: a password reset, a WooCommerce order confirmation, a contact form submission. Different plugins set different From headers, and only a real send exercises the _FORCE constants.
Reading the log when a send fails
WP Mail SMTP’s Email Log — the searchable record of every message with its status and, on a failure, the provider’s response body — is part of the licensed build, not the free one. On the free build the equivalents are narrower but real. The Email Test tab renders a debug block on failure containing the PHPMailer exception and, for API mailers, the HTTP status and response the provider returned; copy that block before navigating away, because it is not persisted. The wp_mail_failed snippet above is the same information from the command line, and dropping it into an mu-plugin that writes to error_log() gives you a rolling record without a database table:
wp eval 'error_log( "wp-mail-smtp probe " . var_export( wp_mail( "you@example.com", "probe", "body" ), true ) );'
Expected output: nothing on stdout, and a matching line in the site’s PHP error log. Read the log in the order the message travelled. A PHPMailer exception with an SMTP code means the relay refused you and the code says why. An HTTP 401 or 403 from an API mailer means the key is wrong, revoked, or scoped to a different region. A successful handoff with nothing arriving means the message left cleanly and the receiver dropped it, which moves the investigation to the provider’s own delivery log — the only place bounce and complaint events exist at all. If you plan to answer “what happened to this customer’s receipt” more than once a quarter, the provider’s log is the record you want to be able to search, not the plugin’s.
Troubleshooting
SMTP Error: Could not authenticate / response 535. The credentials are wrong for the protocol, not necessarily wrong. Google Workspace and Microsoft 365 both refuse account passwords over basic SMTP auth and require an application password or OAuth. Providers like SendGrid want the literal string apikey as the username with the key as the password. Full diagnosis in SMTP 535 authentication failed.
Sends succeed but arrive from the wrong address. Another plugin is setting wp_mail_from at a later priority. Set WPMS_MAIL_FROM_FORCE and WPMS_MAIL_FROM_NAME_FORCE to true. If it persists, a theme functions.php filter is likely doing it — grep the theme for wp_mail_from.
Everything passes but Gmail still files it as spam. Authentication is a floor, not a ceiling. Check that the sending domain is not on a shared IP with a bad neighbour, that the message has a plain-text part rather than HTML only, and that a DMARC p=none policy has been collecting reports long enough to show the real pass rate. Content and reputation take over once alignment is solved.
Connection times out after roughly thirty seconds, and admin pages hang. The outbound port is filtered rather than refused — a firewall dropping packets instead of rejecting them. Step 2 catches this. Switch to an API mailer over 443; there is no configuration that makes a dropped packet arrive.
No mail at all, and no error either. Check for WPMS_DO_NOT_SEND left defined from a staging environment; it makes the plugin discard everything silently by design. Also confirm the site is not still on the mail mailer — wp option get wp_mail_smtp --format=json shows the active mailer, and a wizard abandoned halfway leaves it there.
When this is the wrong approach
If you send more than a few thousand messages a day, or you need per-message delivery events, suppression lists and bounce webhooks, drive the provider’s API from your application code and stop routing through wp_mail(). The plugin is a compatibility shim for the WordPress mail API, and its value drops as your volume rises.
If the real requirement is marketing email — newsletters, campaigns, segmentation — send it from a platform built for it and keep the transactional stream separate. Mixing the two on one domain lets an unsubscribe-heavy campaign damage the reputation of your password-reset mail.
If your fleet is dozens of sites, hardcoding constants per site does not scale; you want the credentials injected at deploy time from a secret store, which is an infrastructure problem rather than a plugin one. And if the free build’s missing email log turns out to be the constraint that matters to you, that trade-off and the alternatives are laid out in WordPress SMTP plugins compared. The plugin itself is on WordPress.org.
Running WordPress that earns real money deserves an operator — Stack Harbor runs that stack under Enterprise WordPress; book an infrastructure consult.