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 formmailer.pl form installed, configured and working.

Be sure to make a backup of your form, and formmailer.pl, 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 formmailer.pl)

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

      # USER CUSTOMISATION SECTION
      # --------------------------
      # Place any custom code here

      use CGI;
      sub spam {
      my $q = new CGI;
      my $spamcheck = $q->param('AntiSpam') || '';
      if ($spamcheck ne '4') {
      print "Location: http://www.example.com/antispam-error.html\n\n";
      exit;
      }
      }
      spam();


      # USER CUSTOMISATION << END >>
      # ----------------------------
      # (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.




NOTES:

    • 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 http://www.example.com/antispam.html 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 användare blev hjälpta av detta svar
Hjälpte svaret dig?

Relaterade artiklar

Seeing list of files, not home page

Like all linux-based web servers, your 'home page' must be named index.htm or index.html,...

Add-on Domains

Most of our web hosting packages allow you to have multiple domain names. The additional domains...

Parked Domains

Most of our web hosting packages allow you to have multiple domain names. The additional domains...

Get Web Hosting and EMail Instructions resent to you

When you first signed up for Web Hosting service with QTH.com, you would have received an email...

AWStats Statistics - Definitions

Here is a link to a page that defines each of the terms in AWStats, including Unique Visitor,...