Add anti-spam feature to our form mailer

To help curtail spammers from filling out your form, you can ask a question that only humans would know, which should stop the form mail robots from abusing your form. But there are still humans out there that get paid to fill out these forms, and nothing will stop those guys, unfortunately.

This tutorial assumes you already have our form installed, configured and working.

Be sure to make a backup of your form, and, before making these changes, just to be sure (so if it blows up, you can just put it back the way it was).

STEP 1: Make two changes to the html page that contains your form.

    • Add "AntiSpam" to the list of required fields in your form, like so:

      <input type="hidden" name="required" value="email,FullName,AntiSpam">

  • Add an Anti-spam question to your form, like so:

    Anti-Spam Question: What is two plus two? <input name="AntiSpam" size=2>

STEP 2: Make two changes to the formmail script (usually called

    • Look for the part in the script that starts with "USER CUSTOMISATION SECTION" and add the following code (the new code is in bold)

      # --------------------------
      # Place any custom code here

      use CGI;
      sub spam {
      my $q = new CGI;
      my $spamcheck = $q->param('AntiSpam') || '';
      if ($spamcheck ne '4') {
      print "Location:\n\n";

      # ----------------------------
      # (no user serviceable parts beyond here)

    • In the form mail script, scroll down (or use your text editor's search feature) and find this section:

      use CGI;
      use POSIX qw(locale_h strftime);
      use CGI::NMS::Charset;

      Place a # in front of the first line, which disables that line. Like so:

      #use CGI;
      use POSIX qw(locale_h strftime);
      use CGI::NMS::Charset;

      Then, save your changes and upload the revised formmail script back into your cgi-bin directory, and upload your revised contact html form as well.


    • Since on our form we are asking "what is two plus two", we have the number '4' entered above, which is the correct answer to the anti-spam question. If you wanted to ask a different anti-spam question, then be sure to put the correct answer in place of '4'.

  • Notice that we are redirecting people to if they do not answer the question correctly. You will need to change this address to be for YOUR WEB SITE, and you will NEED TO CREATE this 'antispam.html' and place some wording on this page like
    "Sorry, you did not answer our anti-spam question correctly. Please use your browser's BACK button to go back and try again."

In theory, this should be all that you need to do. Please contact us and let us know how well this worked for you.

  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

How to upload website using Microsoft Publisher

Open Microsoft Publisher and go to File -> Publish to the web. First you would have to set your...

Free SSL Certificates is pleased to offer FREE "Let's Encrypt" SSL Certificates and HTTPS Hosting Service for...

What is MySQL? What is a Database? What is SQL?

Here is a nice article that explains SQL, MySQL and Databases in a user-friendly format: What is...

How to replace the small blue QTH icon?

The small icon displayed next to the URL in the address bar of your web browser (Chrome, Internet...

How do I create MySQL databases?

MySQL databases are created using your cPanel Control Panel. Usually this is a 3 step process:...