Back to tutorials
Tutorial

Fix WordPress Not Sending Email on a VPS

Fix WordPress email failures on a VPS: set up SMTP relay, verify headers, pass SPF/DKIM, and confirm delivery end to end.

By Anurag Singh
Updated on Nov 27, 2026
Category: Tutorial
Share article
Fix WordPress Not Sending Email on a VPS

WordPress email failures usually aren’t a “WordPress problem.” They’re a mail transport problem. PHP hands a message to mail(), the server attempts delivery, and the message gets blocked, deferred, or routed to spam.

This tutorial shows you how to fix WordPress email on a VPS (and on many shared hosts). You’ll switch to authenticated SMTP, validate DNS (SPF/DKIM/DMARC), and confirm delivery using real logs and message headers.

By the end, password resets, contact form messages, and WooCommerce notifications should land reliably. You’ll also have a repeatable way to prove messages are authentic and accepted.

What you’ll set up (and what you need)

  • WordPress SMTP plugin to send mail through an authenticated SMTP relay (the best default for most sites).
  • Postfix as an authenticated relay (optional, but handy) so the server can send system mail safely too.
  • DNS records: SPF + DKIM + DMARC aligned to your From domain.
  • Verification: mail logs (on a VPS), message headers, and deliverability checks.

Assumptions: You have SSH access to an Ubuntu 24.04/Ubuntu 26.04 LTS, Debian 12/13, AlmaLinux 9/10, or Rocky Linux 9/10 VPS.

If you don’t have SSH, use a control panel workflow (cPanel/Plesk) or run WordPress on a small VPS.

A HostMyCode VPS gives you the access you need to inspect logs and troubleshoot routing properly. If you’d rather not manage the OS, managed VPS hosting is a practical middle ground.

Quick diagnosis: is WordPress sending, or is mail being blocked?

Don’t guess. Identify the failure mode first. Then fix the right layer.

  1. Trigger a known email:

    • WordPress: request a password reset for an admin user.
    • WooCommerce: place a test order (or resend an order email).
    • Contact form: submit a message using a non-Gmail test address if you can.
  2. Check your WordPress From address (we’ll correct it later). The From domain should match your site domain (or a dedicated mail domain).

    Avoid wordpress@localhost or a random server hostname.

  3. On a VPS, check mail logs immediately after testing:

    # Ubuntu/Debian
    sudo tail -n 200 /var/log/mail.log
    
    # AlmaLinux/Rocky (postfix logs via journal)
    sudo journalctl -u postfix -n 200 --no-pager

    If you see status=sent with a remote SMTP response, the server likely handed it off. In that case, the recipient probably filtered it.

    If you see status=deferred, connect to ... timed out, blocked, or nothing at all, you’re dealing with a transport problem.

Common outcomes:

  • No mail logs created: WordPress is calling mail(), but there’s no working MTA on the server, or policy is blocking mail submission.
  • Deferred / timed out: outbound SMTP ports are blocked by the provider/firewall, or remote servers are throttling your IP.
  • Sent but not received: SPF/DKIM/DMARC is missing or misconfigured, the From domain is misaligned, or content triggers filtering.

If you’re seeing timeouts and delays on a busy store, check overall server health too. Slow PHP workers can delay order emails and background tasks.

This guide stays focused on mail delivery. If you’re hitting upstream timeouts, fix that first: Fix WordPress 504 Gateway Timeout on Nginx VPS.

Fix WordPress email by switching to SMTP (recommended)

PHP mail() is unreliable on modern hosting. SMTP with authentication is more predictable. It also gives you cleaner logs and avoids many provider-level blocks.

Step 1: pick your SMTP path (two good options)

  • Option A: External SMTP provider (fastest): Use a transactional email service (or your business mail provider) and authenticate with SMTP credentials.

    This is usually the best fit for WooCommerce and contact forms. Reputation and deliverability are handled upstream.

  • Option B: Your own domain mail stack (more control): Run a full mail server.

    This is heavier operationally. Plan for monitoring, spam filtering, and ongoing IP reputation work.

This tutorial focuses on relaying from WordPress over SMTP. The same approach works for both options.

Step 2: install a WordPress SMTP plugin

Use one SMTP plugin and remove the rest. Running two at once often creates duplicate headers and broken authentication.

  • WP Mail SMTP (popular, flexible)
  • Post SMTP (strong logging)
  • FluentSMTP (simple and stable)

In WordPress Admin:

  1. Go to Plugins → Add New.
  2. Install your chosen SMTP plugin.
  3. Enable email logging if the plugin supports it. You’ll want receipts while testing.

Step 3: configure SMTP settings correctly

Use these as a baseline. Your provider will supply the exact host, username, password, and sometimes a required port.

  • SMTP Host: e.g. smtp.yourprovider.com or mail.yourdomain.com
  • Encryption: STARTTLS (preferred) or SSL/TLS if required
  • Port: 587 (STARTTLS) is the usual default; 465 (implicit TLS) is sometimes used
  • Authentication: ON
  • SMTP Username: full mailbox/login (often an email address)
  • SMTP Password: app password or SMTP credential
  • From Email: a real address on your domain (example: noreply@yourdomain.com)
  • From Name: your brand/store name

Critical detail: enable “Force From Email” and “Force From Name” if your plugin offers it.

Contact form plugins often override headers. That misalignment is a common DMARC failure.

Step 4: send a test email and verify headers

Use the plugin’s built-in test tool. Send to:

  • a mailbox on the same domain (internal)
  • a Gmail or Outlook address (external)

Open the received message and inspect the headers. You want to see:

  • Authentication-Results with SPF=pass and DKIM=pass (or at least one pass).
  • From domain matching the domain you intend to send as.
  • Return-Path aligned with your domain (or acceptable per your SMTP provider’s setup).

If you use Gmail, click “Show original.” In Outlook, view message source.

Set SPF, DKIM, and DMARC so messages don’t land in spam

SMTP gets mail out of WordPress. DNS authentication helps it survive spam filters once it arrives.

Make DNS changes where your domain is hosted. If you manage domains with HostMyCode, start at HostMyCode Domains and edit DNS records there.

Step 1: SPF record (one record only)

SPF is a TXT record at the root of your domain. You should have exactly one SPF TXT record.

Two SPF records often cause SPF permerror at the receiver.

Example SPF for a site sending via a provider (example only):

Type: TXT
Name: @
Value: v=spf1 include:spf.yourprovider.com -all

If you also send from your server IP (not recommended for most sites), add ip4:YOUR.SERVER.IP:

v=spf1 ip4:203.0.113.10 include:spf.yourprovider.com -all

Verify SPF:

dig +short TXT yourdomain.com

Step 2: DKIM record (from your SMTP provider or mail server)

DKIM is usually one or more TXT records under a selector such as selector1._domainkey.

Your SMTP provider will give you something like:

Type: TXT
Name: s1._domainkey
Value: v=DKIM1; k=rsa; p=MIIBIjANBgkq... (long key)

Verify DKIM exists:

dig +short TXT s1._domainkey.yourdomain.com

Step 3: DMARC record (start with monitoring, then tighten)

DMARC tells receivers what to do when SPF/DKIM fails. Start with monitoring so you can spot misconfigured senders before you enforce.

Type: TXT
Name: _dmarc
Value: v=DMARC1; p=none; rua=mailto:dmarc@yourdomain.com; adkim=s; aspf=s; fo=1

Verify DMARC:

dig +short TXT _dmarc.yourdomain.com

Once your legitimate sources pass consistently, change p=none to p=quarantine. Later, move to p=reject if you want stronger spoof protection.

Optional (but useful): configure Postfix as an authenticated SMTP relay on your VPS

If your VPS sends any system mail (cron output, WordPress CLI jobs, plugin notifications), relay through the same authenticated SMTP service.

It improves reliability and reduces spam placement.

This also helps when outbound port 25 is blocked (still common in 2026). Most SMTP relays accept submission on 587.

If you want a WordPress-focused walkthrough for this exact setup, see Set Up Postfix Relay on a VPS for WordPress Mail. Below is a clean end-to-end version you can follow.

Ubuntu/Debian: install Postfix + SASL

sudo apt update
sudo apt install -y postfix libsasl2-modules ca-certificates

During the prompt:

  • Select Internet Site (it’s fine even though we’ll relay).
  • System mail name: yourdomain.com

AlmaLinux/Rocky: install Postfix + SASL

sudo dnf install -y postfix cyrus-sasl cyrus-sasl-plain ca-certificates
sudo systemctl enable --now postfix

Configure relayhost and credentials

Edit /etc/postfix/main.cf and set the values (adjust host/port as needed):

sudo nano /etc/postfix/main.cf
# Relay everything through your SMTP provider
relayhost = [smtp.yourprovider.com]:587

# Enable SMTP auth
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous

# TLS
smtp_tls_security_level = encrypt
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

Create /etc/postfix/sasl_passwd:

sudo nano /etc/postfix/sasl_passwd
[smtp.yourprovider.com]:587 SMTP_USERNAME:SMTP_PASSWORD

Lock it down and build the hash map:

sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
sudo systemctl restart postfix

Verify relay works from the server:

echo "Postfix relay test $(date -Is)" | mail -s "Relay test" you@your-external-mail.com

Then check logs:

# Ubuntu/Debian
sudo tail -n 100 /var/log/mail.log

# AlmaLinux/Rocky
sudo journalctl -u postfix -n 100 --no-pager

You’re looking for a clean handoff to the relay and a status=sent.

Make WordPress and WooCommerce use a deliverable From address

SMTP helps, but a sloppy From address can still trigger DMARC failures and spam placement.

  • Use a mailbox you control: orders@yourdomain.com, support@yourdomain.com, or noreply@yourdomain.com.
  • Avoid From = customer email in contact forms. Put the customer email in Reply-To instead.
  • Don’t mix domains: If your site is example.com but you send From example.net, set up SPF/DKIM/DMARC for the From domain.

Contact form pitfall: Many forms set “From” to the visitor’s address (often gmail.com). That fails DMARC for major providers.

It can also lead to rejection or heavy filtering.

Use:

  • From: forms@yourdomain.com
  • Reply-To: visitor’s email field

Confirm delivery with a repeatable test plan (not just “it worked once”)

Each time you change email settings, run the same checks. That’s the easiest way to prevent regressions.

  1. Send three test types:

    • WordPress password reset
    • WooCommerce order email
    • Contact form submission
  2. Check plugin logs (email logging) for timestamps and SMTP responses.

  3. Check server logs (if you’re using a Postfix relay). Confirm mail leaves the server without deferrals.

  4. Check message headers in the recipient mailbox:

    • SPF: pass
    • DKIM: pass
    • DMARC: pass (once enforced)
  5. Confirm the envelope sender / Return-Path isn’t something like www-data@hostname, unless your SMTP provider explicitly uses it.

Common reasons WordPress email still fails (and how to spot them)

These are the repeat offenders on VPS-hosted WordPress sites.

Outbound ports blocked (25/465/587)

Many networks block port 25 by default. Some providers also restrict 465/587 until you request access.

Test connectivity from your server:

# Install tools if needed
# Ubuntu/Debian: sudo apt install -y netcat-openbsd
# AlmaLinux/Rocky: sudo dnf install -y nc

nc -vz smtp.yourprovider.com 587
nc -vz smtp.yourprovider.com 465
nc -vz smtp.yourprovider.com 25

If 587 works, use 587 with STARTTLS. If nothing connects, fix firewall/provider blocks before you touch WordPress again.

Wrong hostname / TLS mismatch

If you point at mail.yourdomain.com but that hostname doesn’t have a valid certificate, strict TLS clients will fail the handshake.

Verify TLS from the server:

openssl s_client -starttls smtp -connect smtp.yourprovider.com:587 -servername smtp.yourprovider.com </dev/null

You want Verify return code: 0 (ok).

Duplicate SPF records

More than one v=spf1 TXT record at the root can cause SPF permerror. Many receivers treat that as “fail.”

Check:

dig TXT yourdomain.com +short | grep spf

Fix it by merging mechanisms into a single SPF record.

From domain doesn’t match authenticated domain

Example: SMTP authenticates as user@provider-domain, but the message From is orders@yourdomain.com.

If you haven’t set up DKIM for yourdomain.com, that mismatch often lands mail in spam.

Fix it by configuring your SMTP provider to sign DKIM for the From domain you use. Then confirm DKIM passes in the headers.

WooCommerce emails disabled or queued

WooCommerce can disable specific email types. Some sites also depend on WP-Cron, which won’t run consistently on low-traffic sites.

  • Check WooCommerce → Settings → Emails.
  • Consider a real server cron to trigger WP-Cron every 5 minutes:
crontab -e
*/5 * * * * /usr/bin/php -d detect_unicode=0 /var/www/html/wp-cron.php >/dev/null 2>&1

Adjust the path to your WordPress directory and PHP binary. On many VPS setups it’s /usr/bin/php.

On some it’s /usr/bin/php8.3 or /usr/bin/php8.4.

Shared hosting notes (cPanel/Plesk/DirectAdmin)

On shared hosting you may not have mail logs. That removes the fastest diagnostic tool.

SMTP from WordPress is still the simplest workaround. It bypasses local sendmail limitations and gives you clearer errors.

  • cPanel: confirm SPF/DKIM in “Email Deliverability,” then configure WordPress SMTP with “Other SMTP.”
  • Plesk: check domain Mail settings and enable DKIM signing if you host mail there, or use an external SMTP relay.
  • DirectAdmin: validate DKIM keys and SPF records in DNS; avoid PHP mail() if deliverability matters.

If shared hosting keeps getting you blocked, a VPS gives you control over outbound policy and much better visibility. HostMyCode offers both shared hosting and VPS hosting, depending on how much control you need.

Security and deliverability hardening (small changes that matter)

  • Use app passwords for SMTP if your provider supports them. Don’t reuse your mailbox password.
  • Restrict SMTP plugin access: only admins should be able to change SMTP settings.
  • Set a consistent From: one domain, one identity. Reputation improves over time when you stop changing sender identity.
  • Don’t send high volume from a fresh VPS IP: for stores with newsletters, use a dedicated transactional provider.
  • Monitor bounces: if your SMTP provider has a suppression list, review it monthly.

Troubleshooting checklist (printable)

  • SMTP plugin enabled, only one SMTP plugin active
  • SMTP host/port/encryption correct (587 + STARTTLS is typical)
  • From Email uses your domain and is forced
  • SPF: single record at root, includes your SMTP sender
  • DKIM: selector exists, DKIM=pass in message headers
  • DMARC: present; start with p=none, then tighten
  • Server connectivity to SMTP host works (nc -vz)
  • Mail logs show success (VPS) or plugin logs show SMTP accepted
  • Contact forms set Reply-To to visitor, not From

If you’re doing broader reliability work (staging, safer change testing, quick rollbacks), keep email changes in the same process.

Create a staging copy and validate mail there first: Create a Staging Copy of WordPress on the Same VPS.

Summary: the reliable path to working WordPress mail

To fix WordPress email reliably, stop depending on PHP mail(). Send through authenticated SMTP instead. Then verify deliverability with SPF/DKIM/DMARC and header checks you can repeat.

Once SPF/DKIM pass consistently and your From identity stays aligned, contact forms and WooCommerce emails get boring again. That’s the goal.

If you want faster troubleshooting (logs, firewall control, predictable outbound routing), run WordPress on a VPS you control.

A HostMyCode VPS fits this well, and managed VPS hosting is a good choice if you don’t want to handle Postfix or OS updates yourself.

If store emails and contact forms pay the bills, treat mail delivery like infrastructure, not a plugin toggle. Put WordPress on a VPS where you can read logs and control outbound rules, then relay through authenticated SMTP for consistent results. Start with a HostMyCode VPS, or choose managed VPS hosting if you want help keeping the stack stable.

FAQ

Why does WordPress email work sometimes but not always?

Intermittent delivery is usually filtering or throttling. Messages sent via PHP mail() often lack authentication. Some providers accept them, while others spam-folder or drop them. SMTP plus SPF/DKIM removes most of that randomness.

Should I use port 25, 465, or 587 for WordPress SMTP?

Use 587 with STARTTLS unless your provider explicitly requires 465. Port 25 is commonly blocked on VPS networks and is primarily for server-to-server delivery, not client submission.

Do I need Postfix on my VPS if I’m using an SMTP plugin?

No. Your plugin can send directly to the SMTP provider. Postfix relay is useful if you also want system mail (cron output, alerts) to send reliably from the server.

What’s the biggest contact form mistake that breaks deliverability?

Setting the visitor’s email as the From address. That fails DMARC for major providers. Use your domain in From and put the visitor’s address in Reply-To.

How do I prove the fix worked?

Don’t rely on receiving a single message once. Check your SMTP plugin logs, server mail logs (if applicable), and the recipient’s headers for SPF/DKIM passes. That evidence holds up even after future plugin or server changes.