Protect your email addresses from spam

Before you publish your email addresses somewhere on your webpage, blog or personal site, you should think about protecting it from spammers respectively from bots crawling the net looking for email addresses.

There are several methods to accomplish this. I’ll list a few of those methods:


Convert the email address to Unicode characters

This was not a bad idea in the past, but also bots evolve  It can just as easily interpret the special character entities #64;, #46; for the @ and the . characters respectively. A minor plus in this case is that, the user may be able to use their email client.

HTTP redirection

Write a server-side script to return "" link as an HTTP redirect. All modern browsers recognise this, but perhaps not many harvester bots do. This can be done with Apache’s mod_rewrite, Javascript or server-side scripting. Here is an example in PHP:

/* Will be displayed in browser like*/

foo’s email

/* In email_foo.php file */


header ("Location:");



In this case the user has to follow the link and rely on their mail application to get a hold of the email address. The user has to copy the email address from the application instead of doing it directly from the webpage.

Using a JavaScript (my favorite)

/* Will be displayed in browser like*/

contact foo via mail

—- script —

<script language="JavaScript" type="text/javascript">

function email(n, d) {

if(d == 1){

document.location.href=’mailto:’ + n + ‘ from webpage’;


if(d == 2){

document.location.href=’mailto:’ + n + ‘ from webpage’;


if(d == 3){

document.location.href=’mailto:’ + n + ‘ from webpage’;


if(d == 4){

document.location.href=’mailto:’ + n + ‘ from webpage’;




— end of script—

however, there are several good methods, it’s almost impossible to list them all .. if you’re interested in protecting your email address using other ways, here are a few keywords to use when searching in Goggle or Bing..

Hex values

HTML Comments

Fake email

Obfuscate AJAX

CSS pseudo-element


CSS unicode-bidi

CSS display be none




Methods to hide email addresses from page source