Setting up SPF, DKIM, and DMARC for your WordPress site ensures emails sent from your domain (like password resets, notifications, or WooCommerce order confirmations) are authenticated and less likely to land in spam. This guide walks you through the entire process, from DNS records to verification, and covers common pitfalls.
What You'll Need
- Access to your domain's DNS management (usually at your domain registrar or hosting provider).
- Access to your WordPress admin dashboard.
- If you use a third-party email service (like SendGrid, Mailgun, or SMTP plugin), have its account details handy.
- A basic understanding of DNS records (A, CNAME, TXT) is helpful but not required.
Step-by-Step
- Identify your email sending method. Determine if your WordPress sends email via the default PHP
mail()function, or through an SMTP plugin (e.g., WP Mail SMTP, Easy WP SMTP) and a third-party service. If you use a service, you'll need its specific DKIM/SPF values. - Set up SPF (Sender Policy Framework).
- Log into your DNS provider and create a new TXT record for your domain (or edit the existing SPF record if one exists).
- For a typical setup, the record should look like:
v=spf1 include:_spf.google.com ~all(replace with your email service's include). If you use multiple services, list them all in the same record, e.g.,v=spf1 include:_spf.google.com include:sendgrid.net ~all. - Save the record. SPF records can only be applied once per domain; if you have multiple, combine them.
- Set up DKIM (DomainKeys Identified Mail).
- If you use a third-party service, go to its dashboard and find the DKIM settings. Generate a DKIM key or copy the provided DNS record (usually a TXT record with a name like
default._domainkey). - In your DNS provider, create a new TXT record with that hostname and the provided value (e.g.,
v=DKIM1; k=rsa; p=MIGfMA0...). - If you're using your hosting provider's mail server, they may provide DKIM as an option in cPanel or Plesk. Enable it and copy the generated record.
- Save the record. DKIM uses a unique selector; you can have multiple selectors for different services, but each must have a unique hostname.
- If you use a third-party service, go to its dashboard and find the DKIM settings. Generate a DKIM key or copy the provided DNS record (usually a TXT record with a name like
- Set up DMARC (Domain-based Message Authentication, Reporting & Conformance).
- Create a new TXT record for
_dmarc.yourdomain.com(replace with your actual domain). - Start with a monitoring policy:
v=DMARC1; p=none; rua=mailto:you@yourdomain.com. This tells receivers to send you reports but not to reject anything. - After monitoring for a few days, tighten to
p=quarantine(spam folder) and eventuallyp=rejectif everything is working. - Save the record.
- Create a new TXT record for
- Configure WordPress to use SMTP (optional but recommended). Install an SMTP plugin (like WP Mail SMTP) and configure it with your email service's SMTP credentials. This ensures emails are sent through the authenticated service, not the default mail() function which often fails SPF/DKIM.
- Test your email authentication. Use a free tool like Mail-Tester.com or send a test email to a Gmail address and check the headers. Look for
spf=pass,dkim=pass, anddmarc=pass.
Common Mistakes
- Multiple SPF records: Having more than one SPF record for your domain causes a permanent error. Always combine them into one.
- Using
-alltoo early: If you haven't included all legitimate senders, emails may be rejected. Use~all(soft fail) until you're sure. - Forgetting the DKIM selector: The hostname for DKIM must match exactly what your email service provides. A missing or wrong selector will cause DKIM to fail.
- DMARC policy too strict before testing: Setting
p=rejectbefore verifying SPF and DKIM can silently block all your email. - Not using SMTP: If you rely on PHP mail(), your emails often lack proper authentication and will fail DMARC.
Tips
- Keep a spreadsheet of all your DNS records and their purposes to avoid confusion.
- Use a subdomain for bulk emails (e.g.,
mail.yourdomain.com) to protect your main domain's reputation. - Monitor DMARC reports regularly using a service like Postmark's DMARC inspector or a free parser.
- Always use a dedicated email sending service for transactional emails; it improves deliverability.
- If you change email providers, update your SPF and DKIM records immediately.
Troubleshooting
Emails still going to spam? Check your email headers for the authentication results. If SPF passes but DKIM fails, verify the DKIM record's hostname and value. If DMARC fails, it's likely because SPF or DKIM failed. Also check your IP reputation using tools like Talos Intelligence or BarracudaCentral.
DMARC reports not arriving? Ensure the rua address is correct and that your email provider accepts the reports. Sometimes reports are sent in XML, which may be filtered as spam—check your spam folder.
Can't find the DNS management page? Look for "Advanced DNS," "DNS Zone Editor," or "Manage DNS" in your hosting or registrar dashboard. If you're unsure, contact your host's support.
SPF record too long? SPF records have a 255-character limit. If you exceed it, you may need to use a subdomain for some services or use a third-party SPF flattening tool.
DKIM key not working? Some providers require you to remove spaces or line breaks from the key. Copy the value exactly as provided, including the v=DKIM1; k=rsa; p=... part.
Frequently Asked Questions
Do I need all three (SPF, DKIM, DMARC)?
Yes, for best deliverability. SPF verifies the sending server, DKIM verifies the message integrity, and DMARC tells receivers what to do if both fail.
What if my domain already has an SPF record?
Do not create a second one. Edit the existing record to add new include: statements.
How long does DNS propagation take?
Typically 1-24 hours, but it can take up to 48 hours. Test after a few hours; if it fails, wait and test again.
Can I use DMARC without SPF and DKIM?
Technically yes, but it's pointless—DMARC will always fail if SPF and DKIM fail. You need at least one to pass.
What does p=quarantine mean?
It tells receiving servers to send unauthenticated messages to the spam folder instead of rejecting them outright. It's a middle ground between none and reject.
My WordPress uses a plugin like Contact Form 7. Does this affect email authentication?
No, the plugin uses the same email sending mechanism as WordPress core. If you've configured SMTP, the plugin's emails will also be authenticated.