Contact form emails going to spam, or not arriving?
Why form messages end up in spam or disappear, and the four fixes that solve it for nearly every website.
The following areas are covered in this guide:
- The short answer
- Fix 1: Send from your own domain
- Fix 2: Send through a real mailbox (SMTP), not PHP mail()
- Fix 3: SPF
- Fix 4: DKIM
- Then add DMARC
- Check it worked
- Using an email service instead
- Hourly sending limits
- Still going to spam?
The short answer
Gmail, Outlook, Yahoo and most other email providers now check that every message really comes from the domain it says it's from. Form messages usually fail those checks for one of three reasons:
- The message claims to be from the visitor, for example [email protected], but was sent by your web server.
- It's sent with PHP's mail(), so nobody logs in to send it and failures go unreported.
- Your domain is missing its SPF and DKIM records, the DNS records that say who is allowed to send email for it.
Fix those and form messages arrive in the inbox for nearly every website. Most of it is done in a few minutes in your hosting control panel. The steps below apply to any PHP form. The settings named are the ones in the free forms' fcf-config/fcf.settings.php.
Fix 1: Send from your own domain
The message must be sent from an address on your own domain, such as [email protected]. Not the visitor's address, and not a Gmail, Outlook or Yahoo address, because you don't control their DNS records.
Mail that claims to be from [email protected] but comes from your web server fails Gmail's checks, and is rejected or put in spam. So send from your address and put the visitor's address in Reply-To. When you press Reply, your answer still goes to the visitor.
The free forms already work this way: they send from your own address and put the visitor in Reply-To.
Fix 2: Send through a real mailbox (SMTP), not PHP mail()
With PHP's mail(), the web server hands the message over and reports success, even if the mail system rejects it a moment later. You never find out. Sending through SMTP means the form logs in to a real mailbox and sends from it, like your email program does. If something's wrong, you find out straight away.
On most shared hosting (cPanel and similar), it takes four steps:
- In cPanel, open Email Accounts and create a mailbox just for the form, for example [email protected].
- Find the name of the server your website runs on. In cPanel it's Server Name on the main page, under General Information.
- Put the details in your form's settings:
define('SMTP_HOST', 'server123.yourhost.com'); // the server name, not your domain define('SMTP_USER', '[email protected]'); // the full mailbox address define('SMTP_PASS', 'the mailbox password');The free forms already use port 465 with SMTPS, which suits most hosts. - Send a test message.
Top Tip!
Use the server's name, not your domain name. Your host may show yourdomain.com or mail.yourdomain.com as the mail server, but that only works if your domain points at the same server. If it points somewhere else, for example through Cloudflare, the form can't reach the mail server and you'll see Connection timed out.
The SMTP settings page has the settings for popular hosts, including GoDaddy, Namecheap, Bluehost and Hostinger.
Fix 3: SPF
An SPF record is a DNS TXT record on your domain that lists who may send email for it. It starts v=spf1.
- In cPanel, open Email Deliverability. It shows whether your SPF record is valid, and Repair fixes it. Some hosts don't add SPF for you, so check even on new hosting.
- You must have only one SPF record. If you already have one (for example for Microsoft 365 or an email service), add to it rather than creating a second. Two SPF records make SPF fail.
- If your DNS isn't managed by your host (for example it's on Cloudflare or at your domain registrar), cPanel can't change it for you. Copy the record it suggests into your DNS by hand.
Fix 4: DKIM
DKIM adds a signature to each message so the receiver can check it really came from your domain and wasn't changed on the way.
- Sending through a mailbox on your hosting (Fix 2)? The mail server does the signing. In cPanel's Email Deliverability, check DKIM shows as valid, and use Repair or Manage if not. As with SPF, if your DNS is elsewhere, copy the record into it by hand.
- Sending through an email service? The service signs for you once you've verified your domain with it.
- Using PHP mail() on your own server? The free forms can sign the messages themselves. See the DKIM settings in the installation guide. The self-test page then shows the exact DNS record to add.
Using Cloudflare?
Any record your mail server uses, such as mail.yourdomain.com, must be set to DNS only (grey cloud), not proxied. Cloudflare's proxy only handles websites, not email. SPF, DKIM and DMARC are TXT records, which are never proxied.
Then add DMARC
DMARC tells email providers what to do with mail that fails SPF and DKIM, and sends you reports about it. Gmail and Yahoo expect it from anyone who sends a lot of email, and it helps everyone else too. Start with a record that blocks nothing and only turns on reports. Add a TXT record at _dmarc.yourdomain.com:
v=DMARC1; p=none; rua=mailto:[email protected]
Once you're sure everything you send passes, you can change p=none to p=quarantine. Don't start there: if something you send fails, it would go straight to spam.
Check it worked
- Send a message through your form to a Gmail address.
- Open it, click the three dots next to Reply, and choose Show original.
- Near the top, Gmail shows SPF, DKIM and DMARC. All three should say PASS.
The free forms also include a self-test page that checks your settings and your connection to the mail server, and can send a test email. Turn it on with SELFTEST_TOKEN in your settings: see the self-test page.
Using an email service instead
Can't create a mailbox on your hosting, or sending a lot? An email service such as SendGrid, Mailjet or Brevo works the same way. Fill in the SMTP settings from the service's dashboard, then:
- Verify your domain with the service. It gives you DNS records to add, which set up SPF and DKIM for it.
- Set the sender address yourself. Many services use an API key as the login, not an email address, so set EMAIL_FROM to an address you've verified with them.
- Check the free plan's limits. Most have a daily or monthly cap.
Gmail and Microsoft 365 can also be used: see the SMTP settings page.
Hourly sending limits
Most hosting plans limit how many emails you can send each hour, and a website that goes over can have its email switched off until you contact support. That's a common reason a form suddenly stops sending after a spam attack. Check your host's limit.
The free forms have two settings to keep you under it:
- RATE_LIMIT_MAX limits each visitor (10 messages per 10 minutes to start with).
- SITE_LIMIT_MAX limits the whole website (30 per hour to start with). Set it a little below your host's limit.
To find out when a message couldn't be sent, set LOG_FILE to a file outside your website's public folder. Each failure leaves one line with the time and the error, never the message itself. It's the quickest way to learn that your mailbox password has changed.
Still going to spam?
- Mark it as not spam, and add the form's sending address to your contacts. Your email program learns from this.
- Don't send to a forwarding address. If messages go to one address that forwards to Gmail, the forwarding often breaks the checks above. Set EMAIL_TO to the inbox you actually read.
- Look at the messages themselves. If spam is getting through your form, the spam filter may be catching that, not your setup. See how the free forms stop spam without a CAPTCHA.
- Check your domain isn't on a blocklist, especially on shared hosting, where another website on the same server can cause trouble. Your host can check this and move you if needed.
Something else wrong? See the form says it sent, but no email arrives on the help page.