ZeroSpams

Secure contact form for your website

A contact form is a door into your website and your email. Spam is the visible problem; the quieter ones are forms that can be used to send email to anyone, run code, or leak your visitors' details.

Updated · 2 min read · By the ZeroSpams team

The short answer

A secure contact form validates every field on the server, never puts visitor input into email headers, escapes everything it displays, accepts only the files it needs (checked by their content, not their name), rate-limits submissions, sends email from your own authenticated domain, and stores personal data only as long as needed.

The security checklist

  1. Validate on the server. Check length, format and allowed characters in the code that receives the form, not only in the browser.
  2. Block email header injection. Never put a visitor's name or email straight into the "From" or "Subject" of an email without removing line breaks. Otherwise an attacker can add hidden recipients and use your form to send spam.
  3. Escape everything you display. If you show messages in an admin panel, escape them so any code in a message is shown as text, never run.
  4. Check uploads by their content. If the form accepts files, allow only the types you need, check the file's real content (not its name), limit the size, and store uploads outside the public web folder.
  5. Protect against automated submissions. Trap field, time check, one-time token and rate limit, as in how to stop bots from submitting your contact form.
  6. Send email from your own domain, with SPF, DKIM and DMARC set up, and put the visitor's address in "Reply-To" rather than "From".
  7. Use HTTPS on every page with a form.
  8. Keep personal data only as long as needed, and say how long in your privacy policy.

Why "send a copy to the sender" is risky

Many forms offer to email the visitor a copy of their message. If the copy repeats what was typed, anyone can put a stranger's email address in the form and use your website to send their text to that stranger. A safer confirmation never repeats the message, and is limited to one or two per address per day.

Privacy is part of security

Contact forms collect personal data. Under the UAE's personal data protection law and the GDPR in Europe, you should tell visitors what you collect and why, protect it, and delete it when you no longer need it. Keep form data on your own server where you can, and avoid sending it to third parties unless there is a clear reason.

Common questions

Is a WordPress contact form plugin secure?

The popular plugins are well maintained, but security depends on keeping them updated and on your settings. Old, abandoned form plugins are a common way into WordPress sites.

Should my contact form accept file uploads?

Only if you need them. If you do, accept images or PDFs only, check their content, limit the size and store them outside the public web folder.

Does HTTPS make my form secure?

HTTPS protects the message on its way to your server. It does nothing against spam, injection or unsafe uploads, which need checks in the form handler.