Fix Multiple SPF TXT Records PermError: How to Merge Two v=spf1 Records Safely
Why publishing two separate v=spf1 TXT records on the same hostname triggers immediate RFC 7208 §4.5 PermError, and the exact algorithm to merge them into one.
Incident Symptom & RFC 7208 Root Cause
SMTP & Deliverability Symptom
After onboarding a second email tool (such as adding Zendesk or SendGrid alongside Google Workspace) by pasting a second TXT record starting with v=spf1 into Route53 or Porkbun DNS, ALL outbound email from BOTH providers suddenly fails SPF with PermError: multiple SPF records found!
DNS Resolver & RFC 7208 Mechanics
DNS allows multiple unrelated TXT records on the same hostname (such as google-site-verification=..., _dmarc, or apple-domain-verification=...), which leads engineers to paste a second v=spf1 TXT record alongside the first. However, RFC 7208 §4.5 states explicitly: if more than one TXT record begins with 'v=spf1' (case-insensitive), the receiver MUST NOT guess which one to use and MUST return PermError!
Broken vs Verified DNS Configuration
; IMMEDIATE RFC 7208 §4.5 PermError! Both Google AND Postmark mail fail SPF!
example.com. 3600 IN TXT "v=spf1 include:_spf.google.com ~all"
example.com. 3600 IN TXT "v=spf1 a mx include:spf.mtasv.net ~all"
; (Unrelated verification TXT records like the line below ARE fine and ignored by SPF:)
example.com. 3600 IN TXT "google-site-verification=rXOxyZounnZasA8Z7oaD3c14JdjS9aKSW"; Merged into ONE single v=spf1 TXT record:
; 1. Single 'v=spf1' prefix at start
; 2. Deduplicated ip4:/ip6: blocks first (0 DNS lookups), then deduplicated includes
; 3. ONE single terminal 'all' mechanism (~all or -all) at the very end!
example.com. 3600 IN TXT "v=spf1 include:_spf.google.com include:spf.mtasv.net -all"
; Keep non-SPF domain verification TXT records as separate TXT entries (never inside v=spf1!):
example.com. 3600 IN TXT "google-site-verification=rXOxyZounnZasA8Z7oaD3c14JdjS9aKSW"Protocol Mechanics & Operational Deep Dive
RFC 7208 §4.5 filters a domain's TXT RRset by selecting every record that equals 'v=spf1' or starts with 'v=spf1 ' (with a trailing space, case-insensitive). That trailing-space rule is why 'v=spf1' never collides with 'v=spf2.0/pra' (legacy Sender ID) or 'google-site-verification=...', while ANY two TXT records starting with 'v=spf1 ' cause a deterministic PermError across 100% of compliant mail servers.
Merging two or more v=spf1 records safely follows four strict syntactic invariants: (1) begin with exactly one v=spf1 token; (2) place zero-lookup ip4: and ip6: mechanisms before DNS-querying mechanisms so direct relays match instantaneously without burning DNS queries; (3) combine and deduplicate valid include:, a, and mx tokens while verifying total recursive lookups stay <=10 (ideally <=8); and (4) terminate with a SINGLE all token (~all or -all) at the far right end—never leave an ~all in the middle of the merged string, because SPF evaluates left-to-right and stops at the first matching mechanism, rendering everything to the right of a middle ~all dead unreachable code!
Before deleting the duplicate TXT record during a live production fix, lower TTL if needed, update the primary v=spf1 record with the combined mechanisms first, and delete the second v=spf1 record in the same atomic DNS commit (Route53 UPSERT/DELETE change batch or Terraform apply) so resolvers never observe a transient window missing one of your active senders.
SPF Record Merge Rules & Common Merge Mistakes
| Mechanism / Case | RFC 7208 Evaluation | Production Remediation |
|---|---|---|
| Leaving ~all in the middle ('v=spf1 include:a.com ~all include:b.com -all') | ~all matches 100% of remaining IPs at position 2; include:b.com is NEVER evaluated! | Strip all intermediate ~all / -all / ?all tokens and place ONE terminal -all/~all at the very end. |
| Repeating v=spf1 ('v=spf1 include:a.com v=spf1 include:b.com ~all') | Second 'v=spf1' inside the middle of the string is an invalid unknown syntax token -> PermError! | Write 'v=spf1' once at character 0. |
| google-site-verification, MS=ms12345, docusign=... TXT records | Do NOT start with 'v=spf1 '; completely ignored by RFC 7208 §4.5 record selection. | Leave verification TXT records as separate TXT rows; never paste them inside your v=spf1 string! |
| Merging a record containing redirect= with an all mechanism | Per RFC 7208 §6.1, redirect= is ignored if ANY 'all' mechanism appears anywhere in the record! | Convert redirect=_spf.vendor.com into include:_spf.vendor.com when combining multiple senders. |
Edge Cases & Engineering FAQs
When merging ~all from Vendor A and -all from Vendor B, which terminal qualifier should I keep?
If EVERY legitimate outbound sender for that domain is accounted for in the merged SPF record (or DKIM-signed under an enforced DMARC policy), use -all (Fail) or ~all paired with DMARC p=quarantine/reject—see our SoftFail (~all) vs HardFail (-all) guide for subtle SpamAssassin/Microsoft nuances during DMARC rollouts.
What if merging two records pushes our DNS lookup count above 10?
Do NOT merge the new bulk/transactional sender onto the apex domain! Instead, configure the new ESP's custom Return-Path / bounce domain on a dedicated subdomain (such as pm-bounces.example.com or em.example.com) with its own independent v=spf1 TXT record.
Does uppercase 'V=SPF1' count as a duplicate record alongside 'v=spf1'?
Yes! RFC 7208 §3.1 and §4.5 specify ABNF strings in SPF are case-insensitive: 'V=SPF1' and 'v=spf1' both match the version check and trigger a duplicate-record PermError.
Aligned Transactional Delivery Infrastructure
Dedicated transactional delivery streams with custom Return-Path subdomain SPF alignment and 2048-bit DKIM signing.