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

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:

  1. The message claims to be from the visitor, for example [email protected], but was sent by your web server.
  2. It's sent with PHP's mail(), so nobody logs in to send it and failures go unreported.
  3. 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:

  1. In cPanel, open Email Accounts and create a mailbox just for the form, for example [email protected].
  2. Find the name of the server your website runs on. In cPanel it's Server Name on the main page, under General Information.
  3. 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.
  4. 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.


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.

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

  1. Send a message through your form to a Gmail address.
  2. Open it, click the three dots next to Reply, and choose Show original.
  3. 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:

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:

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?

Something else wrong? See the form says it sent, but no email arrives on the help page.