If your contact form, password reset, or invoice emails are landing in spam, or not arriving at all, the cause is usually three DNS records you've never had to think about: SPF, DKIM, and DMARC. Gmail and Yahoo began enforcing them for bulk senders in February 2024, and since then mail that skips them has had a much harder time getting through.
Each record does a different job. SPF says which servers may send mail for your domain. DKIM signs each message so tampering can be detected. DMARC tells receiving servers what to do when a message fails, and sends you reports about it. Here's how each one works, with records you can adapt.
SPF: Which Servers Are Allowed to Send
Sender Policy Framework is a single TXT record at the root of your domain. It lists the servers and services allowed to send mail using your domain:
example.com. TXT "v=spf1 include:_spf.google.com include:sendgrid.net ip4:203.0.113.25 ~all"
Reading left to right: this is an SPF version 1 record. Google Workspace's servers are allowed, SendGrid's servers are allowed, one specific IP address is allowed (perhaps your web server, for form mail), and anything else should be treated as suspicious.
The ending decides what happens to everything else:
~all(softfail): mail from other servers is accepted but marked suspicious. A good starting point.-all(fail): mail from other servers should be rejected. Use it once you're sure the list is complete.?all(neutral): no opinion. Not much point publishing SPF if you end with this.
Two rules trip people up constantly:
- One SPF record per domain. If you add a second
v=spf1record for a new service, SPF fails for everything. Merge the newinclude:into the existing record instead. - Ten DNS lookups maximum. Each
include:,a,mx, andredirectcounts, including the lookups nested inside the records you include. Go over ten and SPF returns a permanent error. Remove services you no longer use before adding new ones.
DKIM: A Signature on Every Message
DomainKeys Identified Mail adds a cryptographic signature to the headers of each outgoing message. The sending service holds the private key. You publish the public key in DNS so receivers can verify the signature, which proves the message came from an authorized sender and wasn't modified in transit.
The key lives at a selector under the _domainkey subdomain:
google._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA..."
You don't write this record yourself. Your email provider generates the key pair and gives you the selector name and the value to paste in. Each service you send through (your mailbox provider, your newsletter platform, your transactional email service) gets its own selector, so they never conflict.
To see which selector a message used, open a received email's full headers and find the DKIM-Signature line. The d= tag is the signing domain and s= is the selector.
DMARC: The Policy That Ties It Together
SPF and DKIM each check something, but neither checks the address your recipient actually sees in the From line. DMARC closes that gap with a rule called alignment: a message passes DMARC only if SPF or DKIM passes and the domain that passed matches the From domain.
That's what stops someone from sending mail "from" your domain through their own server with valid SPF for their domain. The record lives at _dmarc:
_dmarc.example.com. TXT "v=DMARC1; p=none; rua=mailto:dmarc-reports@example.com"
The tags you'll use most:
p=: the policy for failing mail.none(monitor only),quarantine(send to spam), orreject(refuse it).rua=: where receivers send daily aggregate reports. These XML reports show every source sending mail as your domain, and whether it passed.pct=: the percentage of failing mail the policy applies to. Useful for ramping up gradually.sp=: a separate policy for subdomains, if you need one.
A Rollout Order That Won't Break Your Email
Jumping straight to p=reject is the most common way to block your own invoices. A safer sequence:
- Week 1: Publish SPF with
~alland turn on DKIM for every service that sends as your domain. - Week 1: Publish DMARC with
p=noneand aruaaddress. - Weeks 2 to 4: Read the aggregate reports. Look for legitimate senders that fail, such as a CRM, a billing system, or a forgotten WordPress plugin. Fix each one.
- Next: Move to
p=quarantine, optionally withpct=25at first. - Finally: Move to
p=rejectonce the reports stay clean, and tighten SPF to-all.
The raw reports are XML and not much fun to read by hand. Free report parsers exist if you'd rather view them as charts, but even skimming the source IPs in a text editor will show you which services you forgot about.
Checking Your Records
Look up each record from the command line:
dig TXT example.com +short
dig TXT _dmarc.example.com +short
dig TXT google._domainkey.example.com +short
Or use the DNS Lookup tool and select TXT as the record type. It's quicker when you're checking a client's domain from a machine without dig installed. If you're unsure how TXT records relate to the rest of your zone, the DNS records guide covers A, MX, TXT, and the others.
To test the whole chain, send a message to a Gmail address, open it, and choose "Show original." Gmail lists the SPF, DKIM, and DMARC results at the top, each one marked PASS or FAIL.
v=spf1 -all and a DMARC record with p=reject. Two records, five minutes, and the domain can't be used against you.Common Problems and Their Fixes
SPF passes but DMARC fails. The service is sending with its own return-path domain, so SPF passed for their domain, not yours. Turn on DKIM signing with your domain in that service, or set up a custom return-path (sometimes called a bounce domain) if they offer one.
Contact form mail fails everything. Your web server is sending mail directly from PHP, from an IP that isn't in your SPF record, using your domain in the From line. The better fix is to send form mail through your real email provider over SMTP, so it inherits proper DKIM signing.
DKIM fails after a forward. Mailing lists and forwarders that modify the message, by adding a footer or changing the subject, break the signature. That's expected, and it's one reason DMARC accepts SPF or DKIM rather than requiring both.
DNS changes are also a good moment to review your domain's WHOIS details. Our post on why domain privacy matters covers what your registration record exposes and how to hide it.