How to Minimize Contact Form Spam.

Why I needed to Minimize Contact Form Spam.

A few months ago I started getting tons of spam through the contact form on my homepage.

Now contact form spam is nothing new, and you can not really ever fully avoid it, but one morning I woke up to find my “business” email filled with 200 messages with subject lines persuading me to purchase some fucking parka jacket from a shady online website.

The mere fact that I could be accidentally missing legitimate emails from potential clients in all the spam is reason enough to take affair, enough was enough!

I started researching solutions that already existed and found the StopForumSpam website, I noticed they had a public API that I could use, I promptly started to write a PHP “wrapper class” around it to make it easier to use for me.

A few hours of testing later, boom, I had my IP Filtering script ready to go, can check out the script here: Spam Protection.


How it works.

The script I have written simply takes an IP address, and does a GET request to the StopForumSpam API to check if the IP Address that you gave it is in their database, which most likely means that it is used to send spam, it then returns true, if the IP address is not found, it will obviously return false.

So, simple IP Blacklist checking, nothing fancy.


How to implement the IP Filtering script

How you would implement this script is by simply including it into your page, creating a SpamProtection object and then calling the  CheckIP("ip here")  method.

Here is one way to implement my IP filtering system:

After I implemented this script I barely see any spam, there is the occasional spammer that gets through the StopForumSpam IP filter, but generally it does a very good job.

I have enabled logging on my contact form that will log a blocked user’s IP address, email address and User Agent which most certainly is spoofed, as well as the time and date, you can view this log here.

If you have any questions about how to implement my SpamProtection script, feel free to leave a comment or send me an email.

Leave a Reply

Your email address will not be published. Required fields are marked *