Skip to content

SPF failures after putting Cloudflare in front of a cPanel server

Mail still leaves from the origin IP, but an SPF record built on the a mechanism now resolves to Cloudflare edge addresses. Why softfails start after the orange cloud, and the rewrite that fixes it.

Cloudflare never touches your outbound mail: Exim on the cPanel server connects straight to recipient servers from the origin IP, exactly as before. What changed is what your DNS says. The default cPanel SPF record leans on the a mechanism — “the IP the domain’s A record points at may send” — and once the apex is proxied, that A record resolves to Cloudflare edge IPs instead of your server. Mail keeps leaving from the origin, SPF now vouches for Cloudflare, the two no longer match, and receivers start recording softfails. The fix is an SPF record that names the origin explicitly and never routes identity through a proxied hostname.

What’s happening

SPF verification is mechanical: the receiving server takes the IP that connected to it, fetches the sender domain’s SPF TXT record, and checks whether any mechanism matches that IP. Three of the common mechanisms resolve DNS at check time — a, mx, and include — and that is where the proxy quietly rewrites your policy.

With the orange cloud on the apex, a expands to Cloudflare’s edge addresses. The mx mechanism keeps working only as long as the MX target record stays DNS-only, which it must anyway for delivery to function. So the failure signature after fronting is precise: mail sent from the same server, through the same Exim, with the same content, flips from pass to softfail (or fail with a -all policy) on the day the proxy status changed — and nobody touched “anything about email.”

Two adjacent breakages often ride along after a DNS migration to Cloudflare: the SPF TXT was imported twice (two v=spf1 records is a permanent error, evaluated as no policy at all), or the DKIM record never made the trip, so DMARC loses its second leg at the same time as SPF fails. Together they read as “our mail suddenly goes to spam since Cloudflare.”

What to check first

Confirm the actual sending path. If the server relays through a smarthost or a filtering service, SPF must authorize the relay, and this article’s origin-centric fix does not apply as written. On a stock cPanel box sending directly, continue.

How to verify

# What SPF does the world see, and how many of them?
dig +short TXT example.com | grep spf1

# What does the a mechanism resolve to now?
dig +short A example.com

# The IP mail actually leaves from
curl -s https://api.ipify.org

# Confirm recent deliveries and the remote responses
grep " => " /var/log/exim_mainlog | tail -10

# DKIM still published?
dig +short TXT default._domainkey.example.com

If the apex A answers with Cloudflare ranges while api.ipify.org reports your origin, any a mechanism in the SPF record is vouching for the wrong network. For ground truth, send a test to a Gmail mailbox and open Show original — the Received-SPF line names the checked IP and the verdict.

The fix

  1. Rewrite SPF around the origin, not around hostnames that might get proxied. A clean record for a cPanel server sending directly: v=spf1 +mx +ip4:203.0.113.10 ~all. The ip4 mechanism is immune to proxy-status changes; mx stays valid because the MX target must be DNS-only regardless. Drop the a mechanism entirely on proxied domains.
  2. Publish it where DNS actually lives. If Cloudflare is authoritative, edit the TXT record in DNS » Records there — changes in WHM » DNS Zone Manager are decoration once the zone has moved. Keep the cPanel copy matching so nobody restores a stale record later.
  3. Delete duplicate SPF records. Exactly one TXT beginning v=spf1 per domain. Merge mechanisms if the import created two.
  4. Do not add Cloudflare to SPF. No include for Cloudflare, no edge ranges: Cloudflare does not deliver your outbound mail, and listing its ranges authorizes millions of other proxied servers’ egress paths for your domain’s identity.
  5. Verify DKIM and DMARC while you are in the zone. Confirm default._domainkey matches what cPanel » Email Deliverability shows for the account, and that _dmarc survived the migration. cPanel’s Email Deliverability screen validates against live DNS, so it will tell you plainly whether the published records match the server’s expectations.
  6. Re-test end to end. Another message to the external mailbox: Received-SPF: pass, dkim=pass, dmarc=pass. Watch the send confirm in /var/log/exim_mainlog.

When this fix is wrong

If outbound mail flows through SendGrid, Amazon SES, a spam-filter gateway, or your MSP’s relay, SPF must list that provider per its documentation, and the origin IP may not belong in the record at all. If the domain’s mail is fully remote (Microsoft 365, Google Workspace), the cPanel server should not be sending as the domain in the first place — set the domain to remote and fix the application that is injecting mail locally. And if reports show permerror rather than fails, the record itself is malformed or over the 10-DNS-lookup limit — that ceiling and its repairs are covered in the SPF 10-lookup limit fix.

Common mistakes

Leaving +a in the record because it always worked before the proxy. Two v=spf1 records after a zone import. “Fixing” deliverability by adding a Cloudflare include. Editing the zone on the cPanel side after authority moved to Cloudflare. Jumping to -all mid-incident, converting softfails into hard rejections while the record is still wrong. Forgetting that each addon domain has its own SPF to repair — each zone carries its own copy.

Prevention

Make proxy-status changes trigger a deliverability re-check: any time a record flips between grey and orange, run the domain through Email Deliverability and an external SPF check. Keep SPF short, explicit, and origin-anchored (ip4/ip6 over resolving mechanisms) on every domain fronted by a proxy. The DNS-only architecture that keeps mail identity stable is described in Cloudflare in front of cPanel in DNS-only mode, and Cloudflare’s own DNS reference is at developers.cloudflare.com/dns/.

Running Cloudflare in front of cPanel/WHM is a stack Stack Harbor operates daily as an official cPanel NOC partner — cPanel server administration covers the DNS, mail, SSL, and firewall plumbing, and you can start a conversation any time.