How to stop contact form spam without a CAPTCHA

Why bots target contact forms, the checks that stop them without bothering real visitors, and what to do if spam still gets through.

The following areas are covered in this guide:


The short answer

Most contact form spam is sent by simple bots, and a few invisible checks stop nearly all of them: a hidden "honeypot" field that only bots fill in, a minimum time before the form can be sent, and limits on how many messages one visitor, and the whole website, can send. Real visitors never notice any of them, so there's no need to make them solve a CAPTCHA.

The free forms on this website have all of these built in. The rest of this guide explains how they work, what they can't stop, and what to do about it.


Why contact forms get spam

Bots crawl the web looking for forms. When they find one, they fill in every field and send it, over and over, usually to advertise something, to post links, or to test whether the form can be used to send email to other people. They don't care what your website is about.

Most of these bots are simple: they read the page's HTML, fill in the fields, and send the result straight to the form's address, without running the page like a browser would. That's what makes them easy to catch.

A small part of the spam is typed by real people, usually selling web design, SEO or "business loans". No automatic check can tell those apart from a genuine enquiry. More on that below.


The trouble with CAPTCHAs

CAPTCHAs ("pick all the traffic lights") do stop bots, but every visitor pays for it:

For most websites, the invisible checks below stop the spam that matters without any of that. Keep a CAPTCHA for the cases where they're not enough.


Checks that stop bots without a CAPTCHA

1. A honeypot field

The form has an extra field that's hidden from people, with a label saying to leave it empty for anyone using a screen reader. Simple bots fill in every field they find, so a message with that field filled in is from a bot.

The best way to handle it: tell the bot its message was sent, and quietly throw it away. If the bot got an error, its owner would know to change it.

2. A minimum time

A person takes at least several seconds to fill in a form. A bot takes a fraction of a second. The form's script notes when the page loaded and sends the time taken with the message, and the server refuses anything sent too quickly.

This also catches bots that send straight to the form's address without loading the page at all, because their message arrives without the time.

3. A limit for each visitor

Allow each visitor only a few messages in a short time, for example 10 in 10 minutes. Nobody genuine needs more, and it stops one bot flooding your inbox.

4. A limit for the whole website

Bots can come from thousands of different addresses at once, which gets round a per-visitor limit. A limit for the whole website, for example 30 messages an hour, means a flood can't use up your host's hourly email allowance. Without it, your host can switch off your website's email, and genuine messages stop too.

5. Check everything again on the server

Required fields, maximum lengths and email address checks in the browser are easy for a bot to skip. The server must check the same rules again, and throw away any field it wasn't expecting. Maximum lengths matter more than they seem: they stop bots pasting in hundreds of links.

6. Never let the form choose where email goes

Some bots aren't after you at all: they want to use your form to send email to other people. A form is safe from this if the "to" and "from" addresses are fixed on the server, never taken from what's typed in, and line breaks are removed from anything that goes in the email's subject. For the same reason, an automatic reply to the visitor's address is risky: a bot can type in someone else's address, and your form sends them email.


What these checks can't stop

Being honest about the limits:


If spam still gets through

  1. Look at what's getting through. If the messages read like sales pitches written by a person, that's human spam. If it's nonsense or lists of links arriving every few minutes, it's an advanced bot.
  2. For human spam, use your email program. Add rules that file messages containing words like "SEO", "backlinks" or "loan" into a separate folder you glance at weekly. Don't delete them automatically, as a genuine enquiry can use the same words.
  3. Lower the limits, if most spam comes in bursts. Fewer messages per visitor, and a lower limit for the whole website.
  4. Use your CDN's bot protection. If your website uses Cloudflare, its free bot protection settings can block a lot of bad traffic before it reaches your form.
  5. Add a CAPTCHA-style check as a last resort. Invisible checks such as Cloudflare Turnstile ask most visitors to do nothing. The free forms don't include one, as most websites don't need it.

The spam settings in the free forms

Every free form on this website has all six checks above built in, with no account or outside service. The settings are in fcf-config/fcf.settings.php, and most websites never need to change them:

SettingTo start withWhat it does
SPAM_MIN_SECONDS2Messages sent faster than this are refused. 0 switches it off.
RATE_LIMIT_MAX and RATE_LIMIT_WINDOW10 per 600 secondsThe limit for each visitor.
SITE_LIMIT_MAX and SITE_LIMIT_WINDOW30 per 3600 secondsThe limit for the whole website. Set it a little below your host's hourly email limit.
TRUSTED_IP_HEADERemptyBehind Cloudflare, set it to CF-Connecting-IP, so each visitor is counted separately rather than all as Cloudflare.

The honeypot field is part of the form's HTML. Leave the block marked "Spam trap" exactly as it is when you copy the form into your page. The maximum length of each field is set in the form builder.

For the full list of how the form protects your website, see inside the form. If your messages are arriving in your spam folder rather than spam arriving in your inbox, see contact form emails going to spam.