Website form spam and preventing SMTP mail-server abuse will always be a thorn in the side of a business. Anti-spam and anti-bot methods help prevent spam, but they do not irradiate it completely. We always recommend installing and using the Google ReCapture plugin to help prevent form abuse and bots from completing forms.

On many websites we build for companies which are not global, we use a GeoPlugin to further prevent form submissions from countries outside the client's customer demographic. This further reduces the likely hood of spam/abuse via website forms.

Since most of our websites are for businesses in the United Kingdom, below we have provided an example of what PHP code we use to prevent forms from being completed by users that are not within the demographic (outside the UK)...

Firstly, you need to download a PHP Geolocation Class (we recommend the one from geoplugin.com). You can download the PHP Geolocation class here.

Then unzip and upload the class files to your web server (in the below example, we have uploaded this to: "/public_html/classes/geoplugin.class". Then we add the following PHP code just above the start of the form...

<?php
require_once('classes/geoplugin.class/geoplugin.class.php');
$geoplugin = new geoPlugin();
$geoplugin->locate();
$the_country = "{$geoplugin->countryCode}";
if ($the_country == "GB") {
?>

Finally, you need to close the if statement and add an else statement at the end of the form...

<?php } else { echo "<p>Our contact form is only available to clients inside the United Kingdom.<br />We have detected you are located outside of the UK or you are using a VPN.</p>"; } ?>

We hope this little script helps reduce spam on your site and SMTP abuse! If you like this, please give us a thumbs up below!