Website emails going to spam? SPF, DKIM and DMARC: a practical guide
How to get your website and business software emails into the inbox: SPF, DKIM, DMARC, reverse DNS and Gmail and Yahoo rules, with DNS records ready to use.
Published on · updated on November 26, 2026 · 10 min
Emails from your website or business software reach the inbox when the domain is authenticated with SPF and DKIM, two checks that prove the sender is authorised, and has a DMARC record aligned with the visible sender. You also need a valid reverse DNS, meaning a name associated with the IP address of the sending server, and a spam complaint rate below 0.3%. These are the requirements Gmail and Yahoo have applied since February 2024; if you send around 5,000 or more messages a day to Gmail, you must also publish DMARC and offer one-click unsubscribe in marketing emails.
Almost always, the problem isn't the wording but the configuration: a few DNS records and a few lines of code. DNS records are the domain's public settings, which you can change from your registrar's or hosting provider's control panel. You can pass the examples below on to your IT person.
Why your website's emails end up in spam
The most common causes I find:
- The contact form uses the visitor's address as the sender. The website sends "from" mario@gmail.com, but the server isn't authorised by Gmail: SPF, DKIM and DMARC can't pass.
- The code uses
mail(), PHP's basic sending function, on shared hosting and without the technical "envelope" sender: the message goes out with the hosting provider's domain, not yours. - The DKIM signature is missing, or it's active on the email service but not on the software that sends from the website.
- There are two SPF records, or one that points to too many services and exceeds the limit on DNS lookups.
- Newsletters and order confirmations go out from the same address: if the newsletter gets spam complaints, the important emails suffer too.
SPF: who can send for your domain
SPF is a TXT-type DNS record that lists the servers authorised to send on behalf of the domain. According to RFC 7208, the standard that defines it, it checks the envelope address used between servers (MAIL FROM, which you'll see as Return-Path) and the name the server introduces itself with (HELO), not the sender the reader sees. That's why it isn't enough on its own.
An example to adapt to your services: it authorises Google's email and an external sending service.
example.it. TXT "v=spf1 include:_spf.google.com include:spf.smtp-service.example ~all"
Three rules from the RFC:
- Only one SPF record per domain: if there are two, the check fails. Every new service is added to the same record.
- At most 10 entries that require a DNS lookup (
include,a,mxand similar): beyond that, the check fails with a permanent error. -allor~all:-allsays that other servers are not authorised,~all(softfail) that they probably aren't.
If the PHP code uses mail(), the PHP manual explains that the envelope sender is set with the -f option in the fifth parameter, and warns that mail() isn't suited to large volumes: for business software, authenticated SMTP is better, meaning a real mail server with a username and password.
DKIM: the message signature
DKIM puts a digital signature on every message, like a seal: the sender signs with a private key, and the recipient checks it with the public key published in the DNS under selector._domainkey.domain (RFC 6376). In the DKIM-Signature header, the d= tag shows the signing domain and s= the selector, that is, the name of the key.
The record looks like this (the real key is longer):
mail2026._domainkey.example.it. TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOC..."
RFC 8301 requires RSA keys of at least 1024 bits, recommends at least 2048 and forbids rsa-sha1. Google's guidelines also recommend 2048 bits, if your DNS provider allows it. A selector with the year in its name makes it easier to replace the key periodically.
DMARC: policy and alignment
DMARC tells receiving servers what to do with messages that use your domain without authenticating. Since May 2026 the standard has been RFC 9989, which replaces RFC 7489. The record lives at _dmarc.domain.
The key point is alignment: the domain in the visible From: must match the one verified by SPF or DKIM. In relaxed mode, the default and more lenient one, the same main domain is enough: news.example.it is aligned with example.it.
| Policy | What you ask receivers to do | When to use it |
|---|---|---|
p=none | No special treatment, reports only | At the start, to find out who is sending in your name |
p=quarantine | Treat failing messages as suspicious | When the reports show that all your sources pass |
p=reject | Reject them: the use of the domain is not valid | Once everything is settled, after weeks with no legitimate failures |
The typical path: three versions of the same record, published one after the other, weeks apart.
_dmarc.example.it. TXT "v=DMARC1; p=none; rua=mailto:dmarc@example.it"
_dmarc.example.it. TXT "v=DMARC1; p=quarantine; rua=mailto:dmarc@example.it"
_dmarc.example.it. TXT "v=DMARC1; p=reject; rua=mailto:dmarc@example.it"
rua is the address for aggregate reports, the summaries of who is sending in your name: without it, servers don't send them. sp and np allow different policies for existing and non-existent subdomains. RFC 9989 removes the old pct tag and introduces t=y, a test mode in which receivers apply one level below the one published.
Gmail and Yahoo requirements
| Requirement | All senders | Above about 5,000 a day |
|---|---|---|
| Authentication | SPF or DKIM | SPF and DKIM |
| DMARC | Not required (I always set it up) | Mandatory, even with p=none |
From: alignment | Not required | With the SPF or DKIM domain |
| Reverse DNS for sending IPs | Mandatory | Mandatory |
| Spam complaints | Below 0.3% | Below 0.3%, ideally below 0.1% |
| One-click unsubscribe | No | Yes, for marketing and subscriptions |
| Encrypted TLS connection (Gmail) | Mandatory | Mandatory |
The sources are Google's email sender guidelines and Yahoo's best practices. In Google's FAQ, the threshold is about 5,000 messages in 24 hours to personal Gmail accounts, counting together those from the same main domain; once you cross it, you remain a "bulk sender" permanently. Since November 2025 Google has been enforcing the rules more strictly: non-compliant messages may be rejected. One-click unsubscribe isn't needed for transactional emails, meaning service emails (password resets, booking confirmations or form submission confirmations), and it must be processed within 2 days, as Yahoo requires and Google recommends.
For one-click unsubscribe, RFC 8058 requires two headers, technical lines invisible to the reader, covered by the DKIM signature:
List-Unsubscribe: <https://example.it/unsubscribe/a8f3c2e1>
List-Unsubscribe-Post: List-Unsubscribe=One-Click
Reverse DNS (PTR): the IP needs a name
Google and Yahoo require the sending IP to have valid forward and reverse DNS: the IP points to a name, and that name points back to the same IP. If you send through an external SMTP service, that's its job; if you send from your own server, the PTR is set from the control panel of the provider that assigns you the IP. In the example, the first line links the IP to the name, the second does the opposite:
25.113.0.203.in-addr.arpa. PTR mail.example.it.
mail.example.it. A 203.0.113.25
BIMI: the logo next to the sender
BIMI shows your brand logo in the inbox. For Gmail, according to Google's guide, you need DMARC with p=quarantine or p=reject on all messages, a VMC certificate (logo registered as a trademark) or a CMC, and the logo in SVG Tiny PS format. According to the BIMI Group, the record lives at default._bimi and says where the logo and certificate are:
default._bimi.example.it. TXT "v=BIMI1; l=https://example.it/bimi/logo.svg; a=https://example.it/bimi/logo.pem"
It's the last step, not the first.
Keep transactional and marketing separate, and start gradually
Google asks that messages of the same category have the same From: address, that you don't mix different types in the same message and, if you send from several IPs, that you use one per type. This is how I separate them: order confirmations, password resets and business software notifications from noreply@example.it; newsletters from a subdomain such as news.example.it, often with a dedicated service. If the newsletter runs into a problem, the confirmations keep arriving.
For a new domain or IP, warm-up applies: Google recommends starting with a few sends to recipients who engage, and then increasing.
How to check that it works
- Send a test to a Gmail address and open More, then "Show original": in the
Authentication-Resultsheader, look forspf=pass,dkim=passanddmarc=pass. - Check the domain in the
Return-Pathand in thed=of the DKIM signature: they must be aligned with theFrom:. - Verify the domain in Google Postmaster Tools with a TXT or CNAME record: it shows spam rate, reputation, authentication and delivery errors, but only with enough volume.
- Read the DMARC reports that arrive at the
ruaaddress for a few weeks before moving toquarantine.
How I set it up in PHP code
On the PHP websites and business software I build, I set up sending like this: authenticated SMTP instead of mail(), the sender always on the client's domain, the visitor's address in the Reply-To (so you reply with one click without breaking DMARC), transactional and marketing emails on separate streams, and bulk sends queued and sent a little at a time. Then the DNS records: SPF, DKIM, DMARC starting from p=none, and a test on Gmail before go-live.
You do need access to the domain's DNS, though. If you no longer know who manages it, start with the checklist on what to do if your web developer has disappeared.
Frequently asked questions
Why do contact form emails end up in spam?
Usually because the form uses the visitor's address as the sender. Your server isn't authorised to send for that domain, so SPF, DKIM and DMARC fail. The solution is to send from an authenticated address on your own domain and put the visitor's address in the Reply-To field.
Is an SPF record enough?
No. SPF only checks the envelope address, not the sender the reader sees, and it breaks when a message is forwarded. You also need DKIM, which signs the message, and DMARC, which ties both to the domain in the From. For high-volume senders, Gmail and Yahoo require all three.
Can I set DMARC to p=reject straight away?
Better not. Start with p=none and a rua address for reports, so you discover every service that sends in your name: business software, newsletter, invoicing, CRM. When they all pass aligned SPF or DKIM, move to quarantine and then to reject. Skipping steps risks blocking legitimate emails.
If I send fewer than 5,000 emails a day, do I need DMARC?
Below that threshold, Google only requires SPF or DKIM for authentication, but I recommend DMARC anyway. It costs one DNS record, sends you reports on who is using your domain and protects your customers from fake emails in your name. It's also the basic requirement for the BIMI logo.
Where to start
If the emails from your website or business software end up in spam, or you're not sure they're even going out, the first step is to read how the code sends them and what the DNS says. As a PHP developer, I set up sending from the application, with authenticated SMTP, queues and separate senders, plus the SPF, DKIM and DMARC records. Book a free 30-minute analysis: I'll tell you what's blocking your emails and how much it costs to fix.