Skip to Content

Mask email address from Spammers

Posted in

Client brief:

Feedback is important so an email link on a website is the easiest way to achieve this. Unfortunatly spammers have automated software that trals websites looking for anything with an @ sign to harvest and sell on to junk mailers. We had to find a way around this.

Method:

By using javascript code we can pass the elements of the email address to a programme that will reconstruct it and pass it on correctly to the email programme. Here's an example of this technique at work:

Mr Nobody

If you click this link, you will see a normal mail window open addressed to nobody@fake.address9z.com - so the user does not have to do any editing of the email address. But, if you view the HTML source for this link, you'll get the following code:

<script>mail2("nobody","fake.address9z",0,"","Mr Nobody")</script>

As you can see, there is nothing in this code which can be directly used by a spam harvester to reclaim the email address. So, the spam harvesting problem is also solved.

How do I implement this solution?
You could write your own Javascript to do something similar, but to save time, or if you're not familiar with Javascript, you can download mine. Right-click the link below and save it to your hard disk:

http://www.bronze-age.com/email.js

This file should be added to a suitable directory, such as the root or a scripts directory, within your web site. It is very small (less than 1K) so will not adversely affect page-load times.

To use the script to protect email links in a web page you need to carry out the following steps:

In the HEAD section of the web page, add the following line:

You must be careful to specify the correct path to the email.js file - here I've assumed you've saved it into a top-level "scripts" directory in your site.

Now, every email link must be converted to a script call. For instance, a link such as:

Mr Nobody
Needs to be recoded as:

The simplest way to encode your mail links is to use this automatic tool. This converts a list of email addresses into the required Javascript calls for step (2), with a simple button press.

Result:

www.leetoons.com