Skip to content

How to Set Up SPF, DKIM and DMARC So Your Site’s Emails Don’t Land in Spam

On this page

Last updated: · By

Short answer: SPF, DKIM and DMARC are three TXT records in your domain’s DNS that prove to mail servers that an email sent in your name really comes from you. SPF lists which services are allowed to send for your domain, DKIM adds a digital signature to every email, and DMARC tells the receiving server what to do with an email that fails the checks. For a site on Cloudways you copy the values from your sending service (Elastic Email, Mailgun, SendGrid and so on), add them at your registrar or in Cloudflare, and make sure the domain has only one SPF record.

⏱ Time: 15–30 minutes, plus up to 24 hours for DNS to update · Difficulty: medium · Last checked against the official documentation: 6 Nov 2026

What SPF, DKIM and DMARC are, in plain language

Anyone can send an email with info@your-business.com in the “From” field. To tell a real email from a fake one, mail servers like Gmail and Outlook check three things in your domain’s DNS.

SPF (Sender Policy Framework) is a guest list. It is a single TXT record on the domain, starting with v=spf1, listing which servers and services are allowed to send email for the domain. An email that arrives from a server that isn’t on the list is treated as suspect.

DKIM (DomainKeys Identified Mail) is a seal. The sending service signs every email with a cryptographic signature, and publishes the public key in DNS that lets others verify it. If the signature is valid, the receiving server knows the email was sent with the domain owner’s approval and wasn’t altered along the way.

DMARC is a policy. It tells the receiving server: “if an email in my name fails SPF and DKIM, handle it like this”: do nothing, send it to spam, or reject it. It can also ask for reports about who is sending in your name.

RecordWhere it livesExampleWhat happens without it
SPFTXT at the domain root (@)v=spf1 include:_spf.elasticemail.com ~allThe receiving server doesn’t know who is allowed to send
DKIMTXT (or CNAME) on a subname like api._domainkeyv=DKIM1; k=rsa; p=...No proof the email wasn’t forged
DMARCTXT named _dmarcv=DMARC1; p=none;No policy and no reports, and bulk senders to Gmail may be rejected

Why this is urgent now: since 1 Feb 2024 Google requires everyone sending to Gmail to have at least SPF or DKIM, and anyone sending more than 5,000 emails a day to Gmail to have all three, including DMARC (a p=none policy is enough). An unauthenticated email may land in spam or be rejected.

Before you start

  • A list of every service that sends email in your domain’s name: your site’s sending service, mailboxes (Rackspace, Google Workspace, Microsoft 365), a newsletter system, a CRM, an invoicing system. Each of them has to be included in SPF.
  • A sending service connected to the server. If you haven’t chosen one yet, see which email solution to choose. For example, Elastic Email through Cloudways starts at $0.10 per month for 1,000 emails (up to $57 for 1,000,000), as of 6 Nov 2026 according to the product page.

How do you set up an SPF record?

Adding a new SPF record

  1. First check whether the domain already has a TXT record starting with v=spf1. If it does, don’t add a new one. Go to the merging section.
  2. In DNS management create a new record of type TXT.
  3. In Name/Host enter @. In some registrar interfaces you leave the field empty or write the full domain, depending on what the interface asks for.
  4. In Value enter the value your service gives you. For example, for Mailgun: v=spf1 include:mailgun.org ~all.
  5. In TTL leave Automatic or the lowest value, and save.

The common includes

ServiceWhat to add to SPF
Elastic Email (Cloudways)include:_spf.elasticemail.com (in the Cloudways documentation the full value is v=spf1 a mx include:_spf.elasticemail.com ~all)
Rackspace Email (Cloudways)include:emailsrvr.com
Mailguninclude:mailgun.org
Google Workspaceinclude:_spf.google.com
Other servicesThe value shown in their domain verification settings

Merging two SPF records into one

This is a common mistake: every service you add asks you to “add an SPF record”, and someone adds it as another record. A domain is allowed only one SPF record. If there are two, both are invalid, and all your emails fail SPF.

Say you have Elastic Email for site emails and Rackspace for team mailboxes:

v=spf1 a mx include:_spf.elasticemail.com ~all
v=spf1 include:emailsrvr.com ~all

The merging rules:

  1. v=spf1 once, at the start.
  2. a and mx, if they appeared in either record, only once.
  3. All the include entries from all the records, one after another.
  4. Only one all, at the end. Choose the option that suits you (explained in the table below).

The result:

v=spf1 a mx include:_spf.elasticemail.com include:emailsrvr.com ~all

Delete the two old records and keep only the merged one. Merging SPF doesn’t change your MX records and doesn’t affect receiving email, only the approval to send.

What ~all, -all and ?all mean

EndingNameWhat the receiving server does with a sender that isn’t on the list
-allFailRejects it or marks it as a clear failure
~allSoft failAccepts it, but marks it as suspicious
?allNeutralTakes no position on the record
+allPassApproves everyone. Never use this

My recommendation (my own call, and the examples in the Cloudways documentation use both ~all and -all): start with ~all. After a few weeks, once you are sure every service that sends in your name is in the record, you can move to -all. Also, according to the documentation, don’t add + before an include. It’s redundant and can fail checks at some servers.

The 10-lookup limit

An SPF record can cause at most 10 DNS lookups. The mechanisms include, a, mx, ptr, exists and redirect are counted, and every include can contain its own includes. Beyond 10, SPF fails.

If you hit the limit: remove includes for services you no longer use, remove a and mx if those servers don’t actually send email, or have a particular service send from a subdomain (for example news.your-business.com), which has its own separate SPF record.

Setting up DKIM

A DKIM record is unique to each service and each domain, so you always copy it from the service. You can’t “guess” it.

  1. In your sending service, open the domain verification page. In Mailgun, for example: Domains, pick the domain, then the Sending section.
  2. Copy the record’s name (Host) and its value.
  3. In DNS management create a TXT record. In Name/Host enter the name exactly as it appears at the service, for example pic._domainkey or api._domainkey.
  4. In Value paste the whole value, which usually starts with v=DKIM1; k=rsa; p=, without line breaks and without extra spaces.
  5. Save, and go back to the service to click Verify.

Keep three things in mind:

  • Registrars that append the domain themselves: if you enter api._domainkey.domain.com in an interface that adds the domain automatically, you get api._domainkey.domain.com.domain.com. Check how your interface displays existing records.
  • Different services, different records: unlike SPF, every service has its own DKIM record, under a different name, and that’s fine. But when you leave a service, delete its old DKIM, and don’t mix values between services.
  • Elastic Email: the Host name is api._domainkey. Since October 2026, new domains are verified with a 2048-bit key (domains already verified with the old key keep working). If your DNS provider rejects the value because it is too long, you split it into two quoted strings, and most providers do this automatically.
  • CNAME instead of TXT: some services, like SendGrid, give you CNAME records for domain verification instead of TXT. Add exactly the record type the service asks for. In Cloudflare, leave such records as DNS only (grey cloud).

Cloudways has a dedicated guide for Elastic Email’s records, including DKIM and Tracking: verifying a domain in Elastic Email. For Rackspace, Cloudways support can help with DKIM setup. For a comparison of Google Workspace, Microsoft 365 and Rackspace see business email on your own domain.

How do you set up a DMARC record?

DMARC builds on SPF and DKIM, so you set it up last, after both are working.

  1. In DNS management create a TXT record.
  2. In Name/Host enter _dmarc.
  3. In Value start with a monitoring-only policy:
v=DMARC1; p=none; rua=mailto:dmarc@domain.com
  1. Save. The mailbox in rua will start receiving daily reports from the big mail servers, in XML format. It’s better to point them to a dedicated mailbox or to a service that analyzes DMARC reports.

The syntax according to RFC 7489 (checked 6 Nov 2026): the v=DMARC1 tag must be first in the record, and tags are separated by semicolons. If the rua mailbox is on a different domain, the receiving domain needs to publish an authorization record. Elastic Email’s documentation offers both a version without reports (v=DMARC1; p=none;) and a version with rua and ruf. The policy applies to all email sent from the domain, not only Elastic Email’s.

Stagep valueMeaningWhen
1. Monitoringp=noneChange nothing, just collect reportsFrom the start, for at least a few weeks
2. Quarantinep=quarantineAn email that fails goes to spamWhen the reports show all your legitimate senders pass
3. Rejectp=rejectAn email that fails is rejected outrightFull protection against domain spoofing

Don’t jump straight to p=reject. If you forgot a service (say, the invoicing system that sends in your name), all its emails will vanish without anyone knowing.

Why DMARC fails even when SPF passes

DMARC also checks alignment: the domain in the “From” field the recipient sees has to match the domain that passed SPF or DKIM. If your site sends as info@your-business.com, but the sending service signs with its own domain and not yours, SPF can pass and DMARC will still fail. That’s why it matters to verify your domain with the sending service, and to send only from an address on that domain.

How to check that everything works

  1. Wait for propagation. DNS changes sometimes take up to 24 hours. If verification fails right after you add a record, wait a few hours before you change anything.
  2. Send a test email to a tool like mail-tester, which shows a score and a breakdown of SPF, DKIM and DMARC.
  3. Check a real email in Gmail: open an email sent from the site, choose “Show original” from the three-dots menu, and look for SPF: PASS, DKIM: PASS and DMARC: PASS.
  4. Make sure there is only one SPF record starting with v=spf1, with a single all at the end.
Black Friday80% off
80% off 2 months of managed hosting

The code BFCM802 takes 80% off your bill for the first two months (up to $200 off per month), including unlimited free site migrations. New customers only, and only until the offer ends.

The offer ends on December 4, 2026 at 23:59 (UTC+2).

Ends in—days—hours—minutes—seconds
Code:
Grab the 80% now

Start with a free trial, no credit card. Enter the code at checkout and check that it shows up.

After Black Friday: 30% off for 3 months with the code ASAEL. On a large server (above about $444 a month) ASAEL already saves more today. BFCM802 vs. ASAEL calculator

Common mistakes and how to fix them

Two SPF records: the most common of all. Merge them into one using the rules above.

DKIM isn’t verified: the name (Host) isn’t exactly what the service asked for, the value was pasted with spaces or line breaks, or the interface added the domain twice. Check the record with a DNS lookup tool.

Emails are still in spam even though everything is PASS: authentication is necessary, not sufficient. Check the sender address (on your own domain, not gmail.com), the content (shortened links, marketing words, an image with no text), and the complaint rate. Google requires the reported spam rate to stay below 0.30% (and recommends below 0.10%).

You moved to Cloudflare and emails broke: the TXT and MX records weren’t copied, or a CNAME record for an email service was switched to Proxied (orange cloud). Copy everything, and leave email records as DNS only.

You switched sending service: remove the old service’s include and DKIM. Unneeded records waste DNS lookups and can cause confusion.

You hit more than 10 lookups: remove services you don’t use, or move sending to a subdomain.

Sources

Frequently asked questions

What is the difference between SPF and DKIM?

SPF lists which servers are allowed to send for the domain. DKIM adds a signature to every email that proves it was sent with your approval and wasn’t altered along the way. You need both, and DMARC ties them together into one policy.

Can I have two SPF records for the same domain?

No. A second record invalidates both, and all emails will fail the SPF check. You merge all the includes into one record, with a single all at the end.

Is DMARC mandatory?

According to Google, anyone sending more than 5,000 emails a day to Gmail accounts has needed DMARC since February 2024, and a p=none policy is enough. Even a small site should set it up, because it protects against domain spoofing and gives you reports.

How long do SPF and DKIM take to update?

Usually minutes to a few hours, and sometimes up to 24 hours. If verification fails right away, wait before you change the records.

Do SPF records affect receiving email?

No. SPF only determines who is allowed to send in your name. Receiving email is determined by MX records, and merging or changing SPF doesn’t touch them.

Where do I add the records if my domain is registered with a local registrar?

Wherever the domain’s DNS is managed: at your registrar, or in Cloudflare if you moved your DNS there. If you aren’t sure, check where the domain’s nameservers (NS) point.

Official source: Configure Your Domain with Mailgun SPF and DKIM Records, How to Merge Multiple SPF Records (Cloudways Knowledge Base), Email sender guidelines (Google, checked 6 Nov 2026). Written and checked by Asael Dreyer · Updated: 6 Nov 2026

Disclosure: this is an independent site, not the official Cloudways site. Some links on this site are affiliate links: if you sign up through them we earn a commission, at no extra cost to you. Full details

Picture of Asael Dreyer
Asael Dreyer

Hi, I'm Asael Dreyer, CEO of an SEO agency that runs hundreds of websites hosted on dozens of Cloudways servers.
Everything you will find here comes from hands-on experience, mine and my teams', straight from the field: from the guides to the recommendations. All to help you get the most out of Cloudways.

More about me →

Need help? Got a question about your server or this guide? Write to us and we will get back to you.

More guides on this topic:
מפריד
Thanks for your message!
We will get back to you soon.
Ready to get started?

Sign up with the coupon code ASAEL