Home Home -> Net Tips -> Fighting the Spammers

Fighting the Spammers

One of the major problems of running a public website is dealing with unsolicited bulk email, or "spam". I prefer to make my email address available freely, so it is easy to get in touch. Unfortunately, this leaves it open to spammers, the people who send the unsolicited email.

The people and companies who send bulk email are under the misguided impression that it will produce results - in reality, it produces a nasty backlash. If you're thinking of sending spam, don't. In the rest of this article I'll cover my pet hates regarding spam, followed by the methods now being employed on this website to fight the spammers.

Pet Hates

Defence Against Spam

Early Prevention

When examining spam defence, my first priority was to stop spammers getting hold of my address in the first place. Some already have it, but they can be dealt with separately. The easiest way would be to remove every email address from the website and have a contact form instead. I hate contact forms and prefer being able to click a link and send an email from my mail client, so that wasn't really an acceptable option. Any solution needed to fulfil the following requirements:

The solution is fairly simple - for those browsers with JavaScript support, a simple script re-builds the email address when a link is clicked. Those browsers without JavaScript support simply get directed to a page where the email address is displayed on screen, but with additional "junk" HTML in between to disguise it. Since most visitors use Internet Explorer, clicking the link is generally all that is required.

The code below rebuilds a mailto: link from the username and domain:


//---------------------------------------------------------------
// Anti-spam JavaScript function
// You may reproduce this script, but please include this message
//---------------------------------------------------------------
// Copyright (C) 2002, Ashley Brown. http://www.ashleybrown.co.uk/
//---------------------------------------------------------------
function despammail(strUser, strDomain)
{
	document.location = "mailto:" + strUser + "@" + strDomain;
}


Within the HTML code, the email links look like the following:

<a href="/antispam.asp" onclick="despammail('webmaster', 'ashleybrown.co.uk');return false;" class="copyright">