How to stop contact form spam
Form spam comes from bots, scripts and people. No single defence stops all three, so here is how to layer honeypots, captcha, filters and blocking.
Your contact form went live, and within days the inbox filled with offers for backlinks, crypto schemes and messages in languages your site does not use. Deleting them by hand costs time and makes real messages harder to spot.
No single switch ends form spam. There are several defences, each good against one kind of sender and weak against another. This guide explains what each one does and does not stop, and how to set it up.
How contact form spam works
Spam arrives in three ways, and it helps to know which one you are facing.
Crawling bots. These programs visit web pages, look for <form> elements, fill in every field they find and submit. They are cheap to run and not clever. Most do not run JavaScript and do not look at how the page is styled.
Scripted POSTs. A form's action URL is visible in the page source. Anyone can copy it and send requests straight to it from a script, without ever loading your page. These senders skip everything that happens in the browser, including your client-side validation and any hidden-field tricks that depend on the page.
Human spam. A person, sometimes paid per message, opens your page and types or pastes a sales pitch. To your server this looks exactly like a real visitor, because it is one.
Layered defences at a glance
Defence | Stops well | Does not stop |
|---|---|---|
Honeypot field | Crawling bots that fill every field | Scripts written for your form, humans |
Captcha | Most automated submissions | Humans, paid solving services |
Content filtering | Known spam wording and link patterns, including from humans | Spam with new wording |
IP blocking | A repeat sender on a fixed address or range | Senders who change address |
Origin allowlist | Other websites posting to your form from a browser | Scripts outside a browser |
Add a honeypot field
A honeypot is an extra form field that real people never see. Bots that fill in every field will fill it in too, which gives them away.
<form action="https://api.formdb.io/f/your-form-id" method="POST">
<label for="email">Email</label>
<input id="email" type="email" name="email" required>
<label for="message">Message</label>
<textarea id="message" name="message" required></textarea>
<input type="text" name="_gotcha" tabindex="-1" autocomplete="off" style="display:none">
<button type="submit">Send</button>
</form>display:none hides the field from sighted visitors and from screen readers, and autocomplete="off" asks browsers not to fill it automatically.
On FormDB the honeypot field must be named _gotcha, and it is always on. If the field arrives with any value, the submission is dropped and never stored. The sender still receives the normal success response, so a bot gets no signal that it was caught. Dropped submissions do not count toward your monthly limit.
What it does not stop: a script that posts only the real fields, or a human. A honeypot is a first filter, not a complete one.
Add a captcha
A captcha is a challenge that tries to tell people and programs apart. The widget on your page produces a token, the token is sent with the form, and the server asks the captcha provider whether the token is genuine.
The server-side check is the important part. A captcha that is only shown in the browser and never verified protects nothing, because a script can skip the page entirely.
FormDB has a built-in captcha, a proof-of-work check that runs in the visitor's browser and needs no account or keys. Choose it in the form's settings and copy the updated snippet from the Setup tab. FormDB also verifies tokens for reCAPTCHA v2, reCAPTCHA v3, hCaptcha and Cloudflare Turnstile. For those, you create the keys in your own account with the provider, then enter the site key and secret key in the form's settings. Captcha is available on every plan. With Turnstile, the form looks like this:
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script>
<form action="https://api.formdb.io/f/your-form-id" method="POST">
<input type="email" name="email" required>
<textarea name="message" required></textarea>
<div class="cf-turnstile" data-sitekey="YOUR_SITE_KEY"></div>
<button type="submit">Send</button>
</form>A submission with a missing or invalid token is rejected with a 400 response and is not stored. For reCAPTCHA v3, which returns a score instead of a pass or fail, you can set the minimum score to accept. Setup for each provider is in the captcha guide.
What it does not stop: humans, and services that pay people to solve challenges. It also adds a script to your page, so use it when a honeypot alone is not enough.
Filter by content
Content filtering reads the submitted text and looks for the wording spam tends to use. It is the only layer here that can catch a human pasting a sales pitch, because it judges the message and not the sender.
FormDB's filter is keyword and pattern based. It is not machine learning, and it does not use IP reputation. There are eight categories you can switch on individually: profanity, crypto, drugs, fraud, adult content, spammy phrases, suspicious links (link shorteners and commonly abused domain endings) and disposable email addresses.
Two modes control how strict it is:
- Strict: one matching category is enough to flag the submission.
- Relaxed: the submission is flagged when two or more categories match, or when at least half of your enabled categories match.
You can add your own rules on top: blocked words or phrases, a maximum number of links, blocked or allowed countries, allowed languages, and duplicate detection for the same message sent within 24 hours. A submission that breaks a rule is flagged like any other.
Filtering is off by default, so turn it on in the form's settings and choose the categories and rules that suit your audience.
Flagged submissions are not rejected. They go to the form's Spam folder, the sender sees the normal success response, no notification email is sent, no integration runs, and the submission does not count toward your monthly limit. If the filter was wrong, mark the submission as not spam and it moves to the inbox. Note that this does not send the notification email after the fact, so check the Spam folder now and then.
What it does not stop: spam written in words the patterns do not cover. Keyword filters also produce false positives, which is why a folder is safer than deletion.
Block IP addresses
Every request comes from an IP address, the numeric address of the sender's connection. If one address or network keeps sending junk, you can refuse it outright.
In FormDB you can list up to 500 entries per form, on every plan. Each entry is a single IPv4 or IPv6 address, or a range in CIDR notation (a compact way to write a block of addresses):
203.0.113.7
198.51.100.0/24
2001:db8::/32Requests from a listed address receive a 403 response and nothing is stored. Each submission in your inbox shows the IP address it came from, so you can see what to block.
What it does not stop: senders who rotate through many addresses, which organised spam operations do.
Restrict which websites can post
When a browser sends a form from a web page, it includes an Origin header naming the site the page belongs to. An origin allowlist tells the server to accept submissions only from your own domains.
FormDB calls this allowed domains, and it is enforced on every plan. Listing example.com allows example.com and www.example.com. Listing *.example.com allows every subdomain as well. Requests from localhost are allowed by default so you can test during development.
What it does not stop: requests with no Origin header at all, which is what a command-line tool or server-side script sends. Those are always let through. An allowlist restricts browsers. It is not a password. Details are in blocking and allowed domains.
A sensible order to set things up
- Put the honeypot field in every form from the start. It costs nothing.
- Turn on content filtering in strict mode and review the Spam folder for a week or two. Switch to relaxed mode, or disable a category, if real messages are being caught.
- If automated spam still gets through, add a captcha.
- Block addresses or ranges that keep appearing.
- Add your domains to the allowed list.
Next steps
The spam protection page describes each setting and the order the checks run in. If you do not have a form on FormDB yet, you can create a free account and try the honeypot, captcha, content filters, IP blocking and allowed domains on the Free plan.