Back to tutorials
Tutorial

Fix WordPress Not Sending Email With Postfix Relay

Fix WordPress not sending email using a Postfix relay + SMTP provider, with SPF/DKIM checks and step-by-step verification.

By Anurag Singh
Updated on Nov 29, 2026
Category: Tutorial
Share article
Fix WordPress Not Sending Email With Postfix Relay

Password resets that never arrive. Contact forms that “submit” but go nowhere. Order emails that vanish. If you’re trying to fix WordPress not sending email, don’t rely on PHP’s local mail() path. Route mail through an SMTP relay with real domain authentication instead.

This guide builds a simple chain: WordPress → local Postfix → external SMTP provider (transactional mail).

You’ll align SPF and DKIM (and ideally DMARC). You’ll also validate each layer as you go.

This approach works on a VPS, a dedicated server, or shared hosting where you have SSH and can install packages.

On managed hosting, you can still handle DNS and WordPress settings. Then ask support to implement the Postfix relay.

What you’ll build (and why it fixes delivery)

Target mail flow:

  • WordPress generates email (password reset, WooCommerce, form plugin).
  • Postfix accepts the message locally and relays it to your SMTP provider using authenticated TLS.
  • Your domain is authenticated with SPF + DKIM (and ideally DMARC), so Gmail, Outlook, and Yahoo treat the mail as legitimate.

Putting Postfix in the middle gives you a queue, clear logs, and one place to manage outbound policy.

It also avoids the “some plugin emails work, others don’t” mess caused by inconsistent PHP mail behavior.

Prerequisites checklist

  • A WordPress site (VPS, dedicated, or SSH-capable shared hosting).
  • Root or sudo access (or your host’s help to apply the Postfix steps).
  • A sending domain, like example.com, and access to its DNS.
  • An SMTP provider account (Mailgun, Amazon SES, SendGrid, Postmark, Brevo, etc.) with SMTP credentials and a verified domain.

A VPS is the cleanest setup because you control Postfix, the firewall, and the logs.

A HostMyCode VPS gives you that control.

If you’d rather not manage mail config yourself, managed VPS hosting is a solid option for this kind of “email must be reliable” task.

Step 1: Confirm the problem (don’t guess)

Trigger a predictable email from WordPress:

  • Go to Users → Profile and change the admin email (then change it back), or
  • Use Forgot password on the login page, or
  • Trigger your form plugin’s test email.

Then check the server logs.

Most Linux distributions log Postfix to /var/log/mail.log (Debian/Ubuntu) or /var/log/maillog (RHEL/AlmaLinux/Rocky).

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

# RHEL/AlmaLinux/Rocky
sudo tail -n 200 /var/log/maillog

If there’s no log activity, WordPress/PHP probably never handed off the message.

Common causes include a disabled mail function, a broken PHP mail setup, or a plugin issue.

If you see bounces or local delivery attempts, the problem is usually relay or authentication.

Step 2: Choose a “From” address you can authenticate

Use a sender address on a domain you control in DNS.

Don’t send from @gmail.com or any domain you can’t publish SPF/DKIM for.

  • Good: no-reply@example.com, support@example.com
  • Risky: wordpress@servername, root@localhost

Most SMTP providers expect the visible From domain to match the domain you authenticate (SPF/DKIM alignment).

If your headers say example.com but authentication doesn’t match, deliverability drops quickly under 2026 inbox rules.

Step 3: Install Postfix (Ubuntu/Debian and AlmaLinux/Rocky)

Install Postfix and a SASL helper for SMTP auth.

If the installer prompts you, choose Internet Site. Set the system mail name to your domain (you can adjust it later).

# Ubuntu/Debian
sudo apt update
sudo apt install -y postfix libsasl2-modules ca-certificates
# AlmaLinux/Rocky
sudo dnf install -y postfix cyrus-sasl cyrus-sasl-plain ca-certificates
sudo systemctl enable --now postfix

Quick sanity check:

sudo postfix status || sudo systemctl status postfix --no-pager
postconf -n | head

If Postfix is running, move on to relay configuration.

Step 4: Configure Postfix to relay through your SMTP provider

You’ll configure four pieces:

  • Relay host (SMTP provider hostname + port)
  • TLS requirements
  • SASL authentication (SMTP username/password)
  • Sender rewriting so you don’t leak www-data@host

4.1 Edit Postfix main config

Open /etc/postfix/main.cf and add or update the lines below using your provider’s values.

Common ports:

  • 587 (STARTTLS) — the usual choice
  • 465 (SMTPS) — implicit TLS; supported, but 587 is often simpler
sudo nano /etc/postfix/main.cf

Append (or update) this block, replacing placeholders:

# --- Outbound relay via SMTP provider ---
relayhost = [smtp.provider.example]:587

smtp_use_tls = yes
smtp_tls_security_level = encrypt
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

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

# Avoid leaking local hostnames in outbound mail
myhostname = mail.example.com
myorigin = example.com

AlmaLinux/Rocky note: the CA bundle path may be /etc/pki/tls/certs/ca-bundle.crt.

Check with:

ls -l /etc/ssl/certs/ca-certificates.crt /etc/pki/tls/certs/ca-bundle.crt 2>/dev/null

If the Debian path doesn’t exist, set smtp_tls_CAfile to the RHEL bundle.

4.2 Store SMTP credentials safely

Create /etc/postfix/sasl_passwd and keep permissions tight.

The entry must match the relayhost format.

sudo nano /etc/postfix/sasl_passwd
[smtp.provider.example]:587 smtp-username:smtp-password

Lock it down and generate the hash map:

sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd
sudo ls -l /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db

Restart Postfix:

sudo systemctl restart postfix || sudo service postfix restart

4.3 (Recommended) Force a clean From domain via sender canonical map

WordPress (or PHP) may fall back to senders like www-data@hostname.

That breaks DMARC alignment and looks suspicious in headers. Rewrite it to a real address on your domain.

Create /etc/postfix/sender_canonical:

sudo nano /etc/postfix/sender_canonical
/^www-data@.*/ no-reply@example.com
/^wordpress@.*/ no-reply@example.com
/^root@.*/ no-reply@example.com

Enable it in main.cf:

sender_canonical_maps = regexp:/etc/postfix/sender_canonical

Reload:

sudo postfix reload

Step 5: Open the firewall for outbound SMTP (common block)

Most providers allow outbound 587/465.

Many hosts block port 25 by default, which is fine here. With a relay setup, you mainly need outbound access to your provider’s SMTP port.

Test connectivity:

# Replace host/port with your provider
nc -vz smtp.provider.example 587

If it times out, check your local firewall rules and your host’s outbound policy.

  • On UFW systems:
sudo ufw status verbose

Outbound is usually allowed by default.

If you run a restrictive egress policy, explicitly allow the provider’s IPs/ports.

Step 6: Send a test email from the server (bypassing WordPress)

This proves Postfix → provider works before you add PHP and WordPress back into the picture.

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

Watch logs while you send:

# Debian/Ubuntu
sudo tail -f /var/log/mail.log

# AlmaLinux/Rocky
sudo tail -f /var/log/maillog

What success usually looks like:

  • A line mentioning relay=smtp.provider.example
  • A final status of status=sent

If you see SASL authentication failed, double-check the bracketed relayhost format and your credentials.

Also confirm whether your provider expects an API key as the SMTP password.

Step 7: Ensure WordPress uses a real From name/address

Even with Postfix relaying, consistent sender headers matter.

You have two clean options:

  • Set From headers via an SMTP plugin (handy if you can’t change server mail config, or you need per-site control).
  • Keep WordPress simple and let Postfix handle relay + rewriting (ideal for a single server running multiple sites).

If Postfix is already relaying, WordPress doesn’t need to speak SMTP directly.

Still, set a stable From to avoid odd defaults.

At minimum, set:

  • From email: no-reply@example.com
  • From name: your brand/site name

If you want a WordPress-side troubleshooting flow, HostMyCode has a companion guide that focuses on plugin-level diagnosis and common PHP mail pitfalls: Fix WordPress Not Sending Email on a VPS.

Step 8: Add SPF and DKIM for your domain (deliverability step you can’t skip)

Relaying through a provider without SPF/DKIM is a classic “it says sent, but I never receive it” scenario.

Major inbox providers are far less forgiving in 2026.

The key is alignment: your authentication must match the visible From domain.

8.1 SPF record

In your DNS zone for example.com, add or edit a TXT record:

Host/Name: @
Type: TXT
Value: v=spf1 include:provider-spf.example ~all

Your provider will give you the correct include value (for SES, Mailgun, SendGrid, etc.).

If you already have an SPF record, merge values into one.

Don’t publish two SPF TXT records at the root.

Verify SPF publishes:

dig +short TXT example.com

8.2 DKIM record

Enable DKIM signing in your provider’s dashboard.

It will give you a selector and a DNS TXT record similar to:

Host/Name: selector1._domainkey
Type: TXT
Value: v=DKIM1; k=rsa; p=MIIBIjANBgkq...

Verify DKIM publishes:

dig +short TXT selector1._domainkey.example.com

8.3 DMARC (recommended)

DMARC gives you visibility into failures and a path to enforcement.

Start in monitoring mode:

Host/Name: _dmarc
Type: TXT
Value: v=DMARC1; p=none; rua=mailto:dmarc-reports@example.com; adkim=s; aspf=s

Once reports look clean for a while, tighten to quarantine or reject.

Go slowly if you also send mail from other platforms (helpdesk, CRM, newsletters).

Step 9: Verify email headers from a real inbox

Send a password reset email to a Gmail or Outlook inbox you control.

Then open the full message headers.

Look for:

  • SPF: PASS
  • DKIM: PASS
  • DMARC: PASS (after DMARC exists and alignment is correct)

If SPF passes but DKIM fails, DKIM is likely not enabled at the provider. Or the DNS record is wrong.

If DKIM passes but DMARC fails, alignment is off.

A common cause is a visible From domain that differs from the authenticated domain.

Step 10: Common mistakes (and quick fixes)

  • Two SPF records at @
    Fix: merge into one TXT value. Only one SPF record is allowed per hostname.
  • Wrong relayhost syntax
    Fix: include brackets [host]:port. Without brackets, Postfix may try MX lookups and surprise you.
  • Credentials file readable by others
    Fix: chmod 600 /etc/postfix/sasl_passwd. Postfix may refuse unsafe perms.
  • Provider requires TLS but Postfix is optional
    Fix: keep smtp_tls_security_level = encrypt to enforce TLS.
  • “From” domain differs from authenticated domain
    Fix: set WordPress From to your verified domain, and/or use sender_canonical_maps.
  • Form plugin sends to a role address that forwards
    Fix: test delivery to a direct mailbox first. Forwarders often add filtering you don’t control.

Step 11: Operational checks: queue, retries, and logs

Once email is flowing, focus on fast diagnosis for the next failure.

Check the mail queue:

mailq

Force a retry of the queue:

sudo postfix flush

Show Postfix configuration overrides:

postconf -n

If WordPress admin actions are slow enough to delay email triggers, fix that too.

This HostMyCode guide covers a common performance failure pattern: Fix WordPress 504 Gateway Timeout on Nginx VPS.

Step 12: If you’re on a multi-site VPS, isolate mail identity per site

Multiple WordPress sites on one VPS is normal.

The risk comes from sending directly off the server IP. One compromised or misconfigured site can damage reputation for everything.

A relay provider helps because reputation and authentication tie back to domains and the provider’s infrastructure.

Still, keep each site’s From address on its own domain. Publish SPF/DKIM for every domain you send as.

If you clone sites often, watch staging environments.

It’s easy to accidentally send customer-facing mail from staging. This tutorial helps you avoid that trap: Create a staging copy of WordPress on the same VPS.

Step 13: Security hardening for mail relays on a VPS

A relay setup is safer than hosting inbound mail. But Postfix is still a networked service, and it will get probed.

  • Keep Postfix listening only where you need it (default local submissions are fine).
  • Patch the OS regularly.
  • Monitor authentication failures in mail.log/maillog.

If your VPS sees constant brute-force noise across services, an adaptive blocklist can cut it down.

This guide shows a practical setup: Install CrowdSec on Ubuntu VPS to block bruteforce.

Summary: a reliable path to transactional WordPress mail

To fix WordPress not sending email permanently, make two things true.

First, use a relay path you can inspect (Postfix → SMTP provider). Second, make domain authentication match what recipients see (SPF/DKIM, then DMARC once stable).

With those in place, password resets and form notifications stop being a recurring emergency.

If you want hands-on access to mail logs, queues, and outbound policy, run WordPress on a HostMyCode VPS. If you’d rather hand off the operational work, managed VPS hosting keeps transactional email dependable without you babysitting Postfix.

If your WordPress emails are business-critical (logins, orders, lead forms), run them where you can inspect mail logs and publish the right DNS authentication. A HostMyCode VPS is a good match for this Postfix relay setup. If you want it configured end-to-end, managed VPS hosting is the simplest path.

FAQ

Do I need a WordPress SMTP plugin if I’m using Postfix relay?

Not strictly. Postfix can relay mail generated by PHP without a plugin. A plugin can still help enforce a consistent From name/address and give you per-site controls.

My test email says “sent” in logs, but nothing arrives. What should I check?

First check the message headers in the receiving inbox for SPF/DKIM/DMARC results. Then confirm your SMTP provider shows the event (accepted, delivered, bounced).

If your provider accepted it, the problem is usually inbox filtering or misaligned authentication.

Can I do this on shared hosting?

Sometimes. If your shared plan allows installing Postfix or provides an SMTP relay feature, yes.

If you don’t have SSH or package access, use a WordPress SMTP plugin with your provider directly, and make sure SPF/DKIM are correct.

Should I open port 25 on my server?

No for this setup. You’re relaying outbound via 587 or 465 to a provider.

Inbound port 25 is only needed if you’re receiving mail on the server, which this tutorial avoids.

How do I verify Postfix is actually using the relayhost?

Send a test email and watch /var/log/mail.log or /var/log/maillog.

You should see a line with relay=smtp.provider.example and status=sent.