e-mail

E-mail address protection from bots

Your e-mail address mailbox is full of spam? Want to get rid of it? Don’t think you need to protect your email? It was a time when you can spend days waiting for someone to send you an e-mail. Nowadays receiving an e-mail is like eating. And I mean eating A LOT.

Even a normal use mailbox is full of spam and unwanted messages. Of course, you can try to remain your e-mail secret, not posting it on sites or elsewhere. But what about if you have a site? You have contact info with your e-mail on every page or simple contact form. And there are a lot of harvesting bots waiting for this information. And after just a few days you are flooded with spam, which can also make you vulnerable to false messages or fishing mails. In this post, I will show you a trick to hide your e-mail. It involves javascript and substituting your email address with a cypher. In our case – ROT-13.

So, How to protect my email?

This is the basic script:

<script type="text/javascript">
	function decode(a) {
		return a.replace(/[a-zA-Z]/g, function(c){
			return String.fromCharCode((c &lt;= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) 
            ? c : c - 26);
		})
	}; 
	function openMailer(element) {
		var y = decode("znvygb:zlnqqerff@zlqbznva.pbz");
			element.setAttribute("href", y);
			element.setAttribute("onclick", "");
			element.firstChild.nodeValue = "Open email software";
	};
	document.getElementById('erasable').innerHTML = "";
</script>
<a id="email" href=" ">Email: please click&lt;/a>

In this scenario, “znvygb:zlnqqerff@zlqbznva.pbz” is actually an encrypted version of “mailto:myaddress@mydomain.com”. The script will be executed upon clicking on the text “Email: please click”. Further, it will load the default e-mail client of the user – Outlook, Gmail, Thunderbird, or whatever they use. Now, if we combine this with the trick explained in this post, the final script looks like this:

&lt;script id="erasable" type="text/javascript">
	function decode(a) {
		return a.replace(/[a-zA-Z]/g, function(c){
			return String.fromCharCode((c &lt;= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) 
            ? c : c - 26);
		})
	}; 
	function openMailer(element) {
		var y = decode("znvygb:zlnqqerff@zlqbznva.pbz");
			element.setAttribute("href", y);
			element.setAttribute("onclick", "");
			element.firstChild.nodeValue = "Open email software";
	};
	document.getElementById('erasable').innerHTML = "";
&lt;/script>

&lt;a id="email" class="button" href=" " onclick='openMailer(this);'>Email: please click&lt;/a>

And if your site supports font-awesome and you want a fancy icon before “Email: please click”:

&lt;script id="erasable" type="text/javascript">
	function decode(a) {
		return a.replace(/[a-zA-Z]/g, function(c){
			return String.fromCharCode((c &lt;= "Z" ? 90 : 122) >= (c = c.charCodeAt(0) + 13) 
            ? c : c - 26);
		})
	}; 
	function openMailer(element) {
		var y = decode("znvygb:zlnqqerff@zlqbznva.pbz");
			element.setAttribute("href", y);
			element.setAttribute("onclick", "");
			element.firstChild.nodeValue = "Open email software";
	};
	document.getElementById('erasable').innerHTML = "";
&lt;/script>

&lt;a id="email" class="button" href=" " onclick='openMailer(this);'>&lt;span class="fa fa-envelope">&lt;/span> Email: please click&lt;/a>

The encryption method is based on the assumption that spambots can’t interpret the entire client-side script language or can only partly interpret it. Masking or encrypting via JavaScript provides reliable protection against spambots. There are few other methods to hide your e-mail address by masking or substituting, but it’s recommended to display it as a graphic.

And if you want to learn how to hide your Javascript code in “view-source”, please read this post – https://en.blacktiehost.com/tips-and-tricks/hide-your-javascript-in-view-source/.

Leave a Reply