3 Easy Steps To Prevent Contact Form Spam With reCAPTCHA


recaptcha loading gif

Everyone hates those annoying images that ask you to identify words, places or numbers when submitting a website form but if you own a website you'll also know how annoying it is getting contact form spam.

The programs that ask you to identify images are called CAPTCHA and are used to distinguish human input from bots.
Well, Google has come to our rescue and developed a simple replacement called the 'No CAPTCHA reCAPTCHA', the reCaptcha requires only a finger tap or the click of a mouse.


captcha cartoon - opticians joke

It might sometimes ask you to identify images but these are normally easier to see and look something like the below image.

sarah connor recaptcha



The great news is that it's really easy to set up 'No CAPTCHA reCAPTCHA' on your website, you can do it by following these 3 simple steps.

Part 1: Request an API key


You will need a Google account(gmail), once you have an account you will need an API key. Click here to get an API key.
You’ll be asked for a label(just give it any name that suits you) and enter your website.
recaptcha api form on Google

Part 2: Using the API key


You will now be given a site key and a secret key. API Key for reCAPTCHA
On your contact form add this java-script to the head tag

<script src='https://www.google.com/recaptcha/api.js'></script>

Copy the reCAPTCHA widget and paste it into your contact form.

reCAPTCHA widget

Your form should look something like the below contact form

submit code

Part 3: Checking the recaptcha with PHP


Your submit page should look something like the below:
Replace YOUR SECRET KEY with your secret key.

submit code

You can download the working code here from Github..


Thanks for reading.
If you're interested in having your website updated then why not get a FREE website mock up.


Get A FREE Mock Up

Share This Post:
Derek McAuley

About The Author

Hi, I’m Derek McAuley, a freelance web developer, based in Dublin, Ireland. I've spent the past few years as a freelance web programmer for Wonderful Websites. I am a tireless seeker of knowledge, occasional purveyor of wisdom and also, coincidentally, a Web Developer.