I manage numerous web sites and domains and my email address is often exposed on the contact pages of the web sites I maintain and optimize. Not surprisingly, my email address has been scanned by any imaginable spammer which make sure my inbox is never empty.

The following is a simple piece of JavaScript code you could use on your own web page to help you achieve dual benefit:

  • Prevent spammers from scanning your email address
  • Enable your legitimate users to send you email messages by clicking on the active email link

The JavaScript Code

<script>
<!–
function emailscramble(){
var a,b,c,d,e,f,g,h,i
a='<a href=\"mai'
b='info'
c='\">'
a+='lto:'
b+='@'
e='</a>'
f='e-mail us'
b+='domain.com'
g='<img src=\"'
h=''
i='\" alt="Email us." border="0">'
if (f) d=f
else if (h) d=g+h+i
else d=b

document.write(a+b+c+d+e)
}
emailscramble()
//–>

</script>

How it works

This JavaScript function emailscramble breaks into pieces which, if put together, would result in a regular mailto HTML statement. Then it recomposes it to show a friendly message, Email us, on the web page, while enabling the active mailto link to open an email program for sending a message. For an example of who this works, visit my Contact WebSage page.

How to customize the code

It is as simple as replacing mydomain.com with, you guessed it, yourdomain.com. Copy and paste the code in your contact web page and enjoy receiving emails from your legitimate users but not from spammers.
Note:Of course, spammers might have already scanned your email address. My advise would be having different email addresses for different communications modes, i.e. if you participate in a forum, use a forum@mydomain.com email address.