All articles

A contact form without a plugin: spam protection and email alerts

Cover image with a contact form drawing

The contact form on this site doesn’t run on an off-the-shelf form plugin. It runs on a small custom one. Here is why, and what happens behind the scenes.

Why not a ready-made plugin?

I needed four fields: topic, name, email and message. Ready-made form plugins ship with dozens of features and often load their styles and scripts on every page of the site. I wanted a form that only runs on the contact page, matches the site’s design exactly and has no effect on speed.

Spam protection without a CAPTCHA

I didn’t want to make visitors pick out traffic lights. Instead there are three quiet measures:

  • A hidden field: People never see it, bots fill it in. If it has a value, the message is silently ignored.
  • A speed check: Submissions that arrive within a few seconds of the page opening aren’t treated as human.
  • A limit: At most five messages per hour are accepted from the same address.

None of this stops a determined attacker, but it filters out most ordinary bots without bothering a single visitor.

The message goes to the database first

The most common failure with forms is that email quietly stops arriving one day and nobody notices. So every message is first saved in the WordPress dashboard under “Messages”; email is the second step. Even if the alert fails, the message isn’t lost. It waits in the dashboard with an unread count.

Email alerts: SMTP

Sending email straight from a server usually either fails or lands in spam. So alerts go out through an email provider’s SMTP server. One small note: on my server port 465 was closed while 587 was open; testing which port is reachable before you set things up saves time.

For the password I used an app password generated just for this job, not the account’s real password. It can be revoked with one click whenever needed.

A good form asks little of the visitor and never loses a message. The rest is detail.

If you’d like to try the form, it’s on the contact page.

ShareLinkedIn ↗
Tugrul Mermertas

Tugrul Mermertas

A developer since 2014, now building products with AI. About me →

Keep reading

Thinking about something similar?

Tell me briefly. I usually reply the same day.