# 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.

- **Canonical URL**: https://opslint.dev/spf/multiple-spf-txt-records-merge-guide/
- **Category**: `SPF`
- **Interactive Workbench**: [Open in Live Workbench](https://opslint.dev/spf/#domain=google.com)
- **Normative Specifications**: `RFC 7208 §3.2 (Multiple DNS Records: Single v=spf1 Requirement)`, `RFC 7208 §4.5 (Selecting Records: >1 v=spf1 Returns PermError)`

## Incident Symptom & Root Cause

**Production 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!

**Protocol / Engine Root Cause**: 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!

## Remediation Diff (Broken vs Verified Fix)

### Broken DNS Zone: Two Separate v=spf1 TXT Records on Apex!

```text
; 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 Single v=spf1 Record (Exact 4-Step Merge Order)

```text
; 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"
```

## Engineering 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

| Case / Engine | Protocol Behavior | Production Remediation |
| :--- | :--- | :--- |
| **Leaving ~all in the middle ('v=spf1 include:a.com ~all include:b.com -all')** (`#merge-middle-all-bug`) | ~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')** (`#merge-duplicate-prefix`) | 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** (`#merge-non-spf-txt`) | 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** (`#merge-redirect-conflict`) | 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. |

## Frequently Asked Engineering Questions

### 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.

## Related Problem-Cluster Guides

- [Fix SPF PermError: Too Many DNS Lookups (Exceeding the RFC 7208 10-Lookup Limit)](https://opslint.dev/spf/permerror-too-many-dns-lookups-10-limit/) — Understand which SPF mechanisms count toward RFC 7208 §4.6.4's hard 10-lookup ceiling, why nested vendor includes blow the budget, and how to cut lookups safely.
- [Split Long SPF & DKIM TXT Records Over 255 Characters Without Whitespace Corruption](https://opslint.dev/spf/spf-255-character-txt-string-splitting/) — How RFC 1035 255-octet character-strings concatenate WITHOUT spaces per RFC 7208 §3.3, fixing include:fooinclude:bar boundary fusion bugs in BIND, Route53, and Terraform.
- [SPF redirect= Modifier vs include: Mechanism: Precedence, Fallback, and Silent Ignore Traps](https://opslint.dev/spf/redirect-modifier-vs-include-mechanism-precedence/) — Learn the exact RFC 7208 §5.2 vs §6.1 execution difference between include: and redirect=, including why combining redirect= with ~all/-all silently disables redirect=.
- [Google Workspace + Microsoft 365 Dual SPF Setup (M&A Split Delivery Without PermError)](https://opslint.dev/spf/google-workspace-and-microsoft-365-dual-spf-setup/) — Configure clean SPF, DKIM, and DMARC during Google Workspace to Microsoft 365 migrations or M&A co-existence while keeping total DNS lookups at 6/10.
