Archive for the ‘Programming’ Category

SPAM and a couple of ways to protect your email address

Monday, March 30th, 2009

The one question I get asked is “how can I reduce the amount of SPAM that I receive?”.  The kinds of emails people are talking about in this instance are ones that you haven’t asked for, unsolicited emails. If you sign up for a newsletter  then expect to receive it, furthermore, depending on the kind of website or kind of newsletter or business you are signing up to, also be aware that you may receive further emails.

One of the main areas to look at if you are receiving a lot of SPAM is your website.  Traditional HTML will include a piece of code which reads href=”mailto:test@test.com”.  The key element here is the mailto part: there are programs call SPAMBots which are programmed to surf the internet and collect email addresses from which ever website they come across.  Amongst other elements, they specifically look for mailto tags. There are easy ways to protect an email address, the easiest probably being the use of javascript: the following is a useful example of how to protect your email address using javascript:

Instead of:

<a href=”mailto:test@test.com”>test@test.com</a>

Write:

<script language=”javascript” type=”text/javascript” src=”email.js”/>

Create a file called ‘email.js’ and copy & paste the following:

user = “test”;
site = “test.com”;

document.write(’<a href=\”mailto:’ + user + ‘@’ + site + ‘\” title=\”Click here to email us…\”>’);
document.write(user + ‘@’ + site + ‘</a>’);

This example does not guarantee that your email address will never be harvested and it obviously doesn’t stop someone from visiting your website and manually adding your email address to a SPAM database.

Another ‘soft’ target in terms of SPAM are contact us forms and alike. Ensure that you ask the user to validate their details before they are able to click ‘Submit’:

<head>
<script type=”text/javascript” language=”javascript”>
var randomNo;

function randomNumber(){

randomNo = Math.floor(Math.random()*100000000);
document.getElementById(”randomNoText”).innerHTML = randomNo;

}

function validate(){

if(document.getElementById(”securityNumber”).value == randomNo){
return true;
}else{
alert(”Please enter the correct number”);
return false;
}
}

</script>
</head>
<body onload=”randomNumber()”>
<form onsubmit=”return validate();”>

<p>Enter the following number below: <span id=”randomNoText”></span></p>
<input type=”text” id=”securityNumber” />
<input type=”submit” value=”Submit Details” />

</form>

<input type=”hidden” id=”submitValidate” />

</body>

The user will be prompted for the right answer before they are allowed to proceed and submit their details. Once again this does not stop someone from manually entering rubbish details but it prevents automated bots from flooding your inbox with emails. A good area to implement this would be on a comment form to say a blog post.

For alternative ideas put the word “captcha” into Google.