
The tempting fix is to shorten the record. Delete the longest-looking bit. Remove an include you don't recognise. Publish and hope.
That's how a lot of businesses accidentally stop their invoicing tool or website form from sending.
To fix an SPF record properly, you need to treat it as what it really is: a set of instructions a receiving server follows, step by step. The fix follows that path, not the character count.
This guide shows you how to diagnose exactly what's wrong, merge duplicate records safely, get under the lookup limit without guesswork and prove the repair worked on real email.
SPF Is a Set of Instructions, Not a String to Shorten
An SPF record tells receivers which servers may use a domain in an SMTP identity. The receiver evaluates it for each email, using the connecting server's IP and the envelope (MAIL FROM) domain, or the HELO name in some cases.
RFC 7208 defines how this evaluation works: mechanisms, qualifiers, nested lookups, results and limits.
Here's why that matters. A record can look tidy and still fail because:
- Its includes add up to too many DNS lookups once expanded
- One of its includes returns an error
- It has a twin record at the same name
- It's been published at the wrong name
These are completely different problems. None of them is fixed by "making it shorter".
Start With the Email, Not the DNS Panel
Before you open DNS, get a real bounce or a trusted Authentication-Results line from a failing email. Copy:
- The SPF result (pass, fail, softfail, neutral, none, temperror, permerror)
- The domain SPF checked (smtp.mailfrom or the Return-Path)
- The connecting IP
- Any reason text
This catches the single most common SPF mistake: fixing the wrong domain.
SPF doesn't check your visible From address. If the failing email used bounce.supplier.example as its envelope domain, editing the SPF record on yourbusiness.co.uk changes nothing. You'd be repairing a door nobody walked through.
Save the evidence and name the sending route before you touch anything.
To understand how SPF fits alongside DKIM, see the SPF vs DKIM guide.
Look Up the Exact Name the Email Used
Query the TXT record for the SPF domain from the email.
dig +short TXT yourbusiness.co.uk
nslookup -type=TXT yourbusiness.co.ukOr use Google Admin Toolbox Dig in a browser.
Record the resolver, the UTC time, the full answer and the TTL. If you suspect caching or a split setup, also query your authoritative nameserver directly.
Look for TXT values starting with v=spf1. A few things to watch for:
- Long records split into chunks. Long TXT values are often shown as several quoted pieces. That's one record, not duplicates.
- Genuine duplicates. Two separate records, each starting with v=spf1, at the same name.
- Wrong name. A record meant for mail.yourbusiness.co.uk accidentally published at mail.yourbusiness.co.uk.yourbusiness.co.uk because the DNS panel added the domain automatically.
Don't paste whole private zone exports into public checkers or tickets. Share only the name and the relevant public answers.
Problem One: Two SPF Records (and Why You Can't Just Delete One)
This happens all the time. You set up a new email platform, and it says "add this SPF record". So someone adds a second record next to the existing one.
v=spf1 include:mailboxprovider.example ~all
v=spf1 include:newsletterplatform.example ~allRFC 7208 says SPF record selection must produce exactly one record. Two records cause a permanent error. Receivers don't merge them for you.
So now both senders fail SPF.
The fix is to merge them into one:
v=spf1 include:mailboxprovider.example include:newsletterplatform.example ~allBut here's the careful part. Don't delete one at random, and don't just paste the two strings together. Do this instead:
- Copy both records into a change note
- For every mechanism (include, a, mx, ip4, ip6, exists, redirect), identify which system it's for, who owns it and recent email evidence that it's still used
- Mark anything unknown for investigation
- Build one record with only confirmed routes
- Put the "all" mechanism at the end, once
Why at the end? Because "all" matches everything. Anything after it is never reached. If you just stick two records together, you might put one record's -all in the middle and accidentally switch off everything after it.
Stop if an active route has no owner or evidence. Use your sender inventory and provider logs to fill the gap first.
Problem Two: "Too Many DNS Lookups" (the Ten-Lookup Limit)
RFC 7208 limits SPF evaluation to ten terms that cause DNS lookups: include, a, mx, ptr, exists and redirect. Exceed it, and the receiver returns a permanent error.
The trap is that includes contain more includes. Your record might show four includes on the surface, but once expanded, they can add up to well over ten.
Here's an illustrative expansion:
yourbusiness.co.uk
include:mailboxprovider.example (1)
include:spf1.mailboxprovider.example (2)
include:spf2.mailboxprovider.example (3)
include:crm.example (4)
include:mail.crm.example (5)
include:newsletter.example (6)
include:a.newsletter.example (7)
include:b.newsletter.example (8)
a (9)
mx (10)
include:helpdesk.example (11) <-- over the limitMap your own tree like this. For each branch, note the owner, purpose and whether it's still needed. Test with the actual sending IP from a real email, because different IPs can follow different paths.
Don't just trust a single red number from a web tool. Save its expanded path and test conditions.
And treat ten as a ceiling, not a target. Leave headroom. Providers change their published records, and a record that's at nine today might be at eleven next month without you touching it.
Problem Three: Old Senders Still Authorised
Every include represents a service allowed to send as you. Over the years, those pile up. The CRM you trialled in 2021. The agency that ran one campaign. The newsletter tool you replaced.
For each mechanism, ask: does this service still send using this exact envelope domain?
Confirm through:
- Service configuration
- Recent test email headers
- Provider events
- The business owner
Be careful. A platform's marketing account might look dead while it still sends password resets. "We stopped paying for it" doesn't prove nothing's sending.
When you do retire one, disable sending in the service before removing its DNS authorisation where possible. Record the owner's confirmation, last observed use and the old value for rollback.
Removing stale includes often fixes the lookup problem as a happy side effect. But the reason to do it is accuracy, not just shaving lookups.
The Trap Called SPF Flattening
You'll find tools offering to "flatten" your SPF record. They replace provider includes with the IP addresses those includes currently resolve to. Fewer lookups, problem solved.
Except it isn't, really. You've now taken on the job of tracking every IP change every provider makes. Shared services change their networks. When they do, your flattened record goes stale. Legitimate mail starts failing, or old infrastructure stays authorised long after it should.
Only use flattening if it's a provider-supported approach, with clear ownership of refreshing it and monitoring to catch drift.
Also question broad a and mx mechanisms. They authorise whatever addresses DNS returns, which might include web servers or inbound mail systems that shouldn't be sending at all. Replace them with narrower mechanisms only when evidence and provider documentation support it.
A Worked Example: Before and After
Here's a fictional record that's grown messy over five years:
BEFORE (two records at yourbusiness.co.uk):
v=spf1 a mx include:mailboxprovider.example include:oldcrm.example
include:newsletter.example ip4:203.0.113.10 -all
v=spf1 include:helpdesk.example ~allProblems:
- Two records: permanent error, so everything fails SPF
- oldcrm.example was replaced two years ago
- a and mx authorise the web server and inbound mail servers, which don't send outbound mail
- ip4:203.0.113.10 belongs to a server nobody can identify
- Expanded, the includes add up to more than ten lookups
After investigation:
- The old CRM is confirmed retired (account closed, no recent headers)
- The web server doesn't send email (the website form uses the helpdesk tool)
- The mystery IP turns out to be an office scanner that emails scans. It's still needed, so it stays, with an owner noted.
AFTER (one record):
v=spf1 include:mailboxprovider.example include:newsletter.example
include:helpdesk.example ip4:203.0.113.10 -allOne record. Fewer lookups. Every mechanism has a known owner. Each route was tested after publishing.
Notice that the mystery IP wasn't deleted just because nobody recognised it at first. Investigation found it was legitimate. Deleting it blindly would have broken scanning.
SPF Syntax Quick Reference
v=spf1 Version. Must start the record.
include:domain Check another domain's SPF policy (counts as a lookup)
a Authorise the domain's A/AAAA addresses (counts as a lookup)
mx Authorise the domain's MX servers (counts as a lookup)
ip4:x.x.x.x Authorise an IPv4 address or range (no lookup)
ip6:... Authorise an IPv6 address or range (no lookup)
exists:domain Advanced check (counts as a lookup)
redirect=domain Use another domain's policy instead (counts as a lookup)
-all Fail everything not matched
~all Softfail everything not matched
?all Neutral (rarely useful)Why Your Record Can Break Without Anyone Touching It
Here's something that surprises a lot of people: an SPF record can go from working to "too many lookups" without anyone in your business changing a thing.
How? Your includes point at records owned by your providers. When a provider restructures its own SPF record (adding a nested include for a new data centre, say), your lookup count goes up automatically.
That's why "it was fine last month" isn't evidence it's fine now. A few habits help:
- Re-expand your full lookup tree whenever a sender changes, and on a regular schedule
- Note beside each include which provider owns it
- Keep headroom below ten so one provider's change doesn't tip you over
- Watch DMARC reports for a sudden rise in SPF permerror results
-all or ~all? Choose Deliberately
The ending of your SPF record sets what happens to unlisted senders:
- -all: fail
- ~all: softfail
Receivers decide how to handle each. Don't switch to a softer ending just to hide a permanent error. Fix the structure first, then choose the ending based on your sending design.
Bigger Redesign? Consider Subdomains
One huge SPF record on your main domain collects dependencies from every supplier you've ever used. It's easy to find but fragile.
An alternative is purpose-specific envelope subdomains (like bounce.news.yourbusiness.co.uk for your newsletter platform, set up through the provider's custom return-path feature). Each has its own SPF policy and lookup budget.
That isolates ownership, but adds DNS records, reporting and maintenance. Only redesign with the affected services involved, not in the middle of an emergency.
Prepare One Record With a Clear Rollback
Before publishing:
- Save the current public answer, authoritative answer, DNS provider view and TTL
- Draft the new record in a review note
- Check syntax, term order, lookup tree and the expected result for every known sending IP
- Check what happens for an unauthorised test IP
- Have someone else compare it with the sender inventory
Set your rollback trigger in advance: a legitimate sender failing, the wrong public name, an unexpected permanent error or impact on another verified sender. Name who can restore the old value. If no one can approve or execute a rollback, don't save.
Publish Once, Then Check the Public Result
Replace the broken record(s) with the single reviewed one at the correct name. Don't edit unrelated TXT records (like domain verification tokens). Save the DNS audit entry and time.
Remember resolvers may serve the old answer until its TTL expires.
Then query your authoritative server and at least one independent public resolver. Confirm:
- Exactly one record starting with v=spf1
- The full expected string
- The intended TTL
Expand the lookup tree again from public DNS. Check for syntax errors, loops, temporary failures and permanent error conditions.
If answers still differ after the old TTL window, stop. Look for delegation issues, multiple DNS providers, split DNS or edits made in a panel that isn't authoritative. Saving the same value again won't fix delegation.
Prove Every Sender Still Works
Send one plain, non-sensitive email through each important route to a mailbox you control. Use the same application, account, envelope domain and From address as normal.
Open the received original and record:
- The trusted SPF result
- The smtp.mailfrom identity
- The sending IP
For the route that was failing, compare with the original. The repair is proven when the record evaluates without error and the authorised IP gets the expected result.
Also check DMARC separately. An SPF pass for an unaligned domain might not satisfy DMARC. See why SPF can pass while DMARC fails.
Routes you can't test should be listed as an explicit risk with an owner and a review date, not quietly assumed healthy.
And keep watching. Your record can stay identical while a provider's nested record changes underneath it and pushes you over the limit. Note that dependency beside each supplier.
Stop and escalate if lookups depend on undocumented supplier chains, a provider's include is broken, an unknown sender remains or several critical systems would need simultaneous changes.
Frequently Asked Questions
What does SPF permerror mean?
A permanent error in evaluating your SPF record, usually caused by multiple SPF records at one name, too many DNS lookups or invalid syntax. Receivers treat it as a failure to evaluate.
Can I have two SPF records?
No. One name must have exactly one SPF record. Merge them into one.
How do I count SPF lookups?
Count every include, a, mx, ptr, exists and redirect, including those inside included records. ip4 and ip6 don't count. The total must stay at ten or fewer.
Is it safe to remove an include I don't recognise?
Not until you've confirmed nothing still uses it. Check service settings, recent headers and with the people who might own it.
Should my SPF record end in -all or ~all?
Both are valid. -all asks receivers to fail unlisted senders; ~all asks for a softfail. Many businesses use ~all while they're still discovering senders and move to -all once their inventory is complete. Choose deliberately.
Does fixing SPF fix DMARC?
Only if the SPF-checked domain aligns with your From domain. Many platforms need custom DKIM instead.
Will fixing my SPF record improve inbox placement?
It fixes one specific failure. If SPF was broken, fixing it removes a red flag. But placement also depends on DKIM, DMARC alignment, reputation and whether recipients want your mail.