How to Mask an Email Address

by Contributor

Spammers can be a real nuisance, especially you want to display your email address on your site so visitors can contact you by email. Many spammers use email harvesters to build their databases. These programs visit websites in order to compile lists to which the spammer sends junk email. By taking a few simple steps using Javascript, you can hide an email address from harvesters while still making it visible to legitimate contacts.

Create a sub-folder of your main site root and name it "js." You'll store Javascript files in this sub-folder so you can easily find them later.

Open WordPad, Notepad, an HTML editor or some other text editor and open a new blank document. Be sure you don't use Microsoft Word, it doesn't work too well with web programming languages.

Add this block of code to your document: <!-- Begin user = "yourname"; site = ""; document.write('<a href=\"mailto:' + user + '@' + site + '\">'); document.write('email me'+'</a>'); // End -->

Delete "yourname" and replace it with the user name for your email address. If your email address were, then you'd replace "yourname" with "john."

Replace "yoursite" with the domain for your email address. Using our example,, you would delete "yoursite" and replace it with ""

Save the file in your Javascript folder as "mailto.js."

Open the HTML file where you want to place your email link and paste this line in an appropriate place: <p>Need to Contact Us?<scripttype="text/javascript"src="/js/mailto.js"></script></p> You can amend "Need to Contact Us?" to read anything you desire.

More Articles