Hopefully the following code will work for many years before the spam-bots get re-written to harvest even these email addresses.
I hope the recent increased number of hits to this page is a result of more users being pro-active and looking for solutions to reduce their spam. In case it is due to SPAMBOTS harvesting email using the javascript:sendMail as their search keywords I am removing my realtime email address from the examples and changing the function name to ss for Stop Spam. You should change the function name to something personal otherwise the spammers could simply add javascript:ss to their search keywords.<script language="JavaScript"> <!--
function sendMail(name, company, domain) {
locationstring = 'mai' + 'lto:' + name + '@' + company + '.' + domain;
window.location.replace(locationstring);
}
//--> </script>
Changed to: <script language="JavaScript"> <!--
function ss(name, company, domain) {
locationstring = 'mai' + 'lto:' + name + '@' + company + '.' + domain;
window.location.replace(locationstring);
}
//--> </script>
Set up your mail link to call the function like this:
<a href="javascript:sendMail('me','myserver','ca')">me@myserver.ca</a>
or
<a href="javascript:ss('me','myserver','ca')">me@myserver.ca</a>
Of course, all your effort could be defeated by the presence of the @ sign in the text portion of your link as the bots may detect this and add your email address to their list of victims. <a href="javascript:sendMail('me','myserver','ca')">Send mail to J & J Systems</a>
or
<a href="javascript:ss('me','myserver','ca')">Send mail to J & J Systems</a>
If you need to include more information in your email link, adjust your javascript to either of the following, remembering to change the function name to 'ss' or your personal function name for sendMail both in the javascript and in the javascript: call :
function ss(name, company, domain, subject, body)
{ locationstring = 'mai' + 'lto:' + name + '@' + company + '.' + domain + "?subject=" + escape(subject) + "&body=" + escape(body);
window.location.replace(locationstring); }
or
function ss(name, company, domain, subject, cc, bcc, body)
{ locationstring = 'mai' + 'lto:' + name + '@' + company + '.' + domain + "?cc=" + cc + "&bcc=" + bcc + "&subject=" + escape(subject) + "&body=" + escape(body);
window.location.replace(locationstring); }
Character Encoding
Besides plain english or ascii, every character can be represented
in HTML in two more ways - an "HTML-encoded" format, and a"URL-encoded" format. Let's look at the HTML-encoded format first.
HTML Encoding
The character @ would be HTML-encoded as @. Your mail link should look similar to:
<a href="javascript:sendMail('me','myserver','ca')">me@myserver.ca</a>
You could forget about using JavaScript altogether and do this instead:
This is how it would appear on the page:
Send mail to J & J Systems
..and this is how you would accomplish it:
<a href="mailto:me@myserver.c
a">Send mail to J & J Systems</a>
URL Encoding
You could alternatively use URL encoding. It is your choice...one is as good as the other.
<a href="mailto:%6D%65%40%6D%79%73%65%72%76%65%72%2E%63%61">Send mail to J & J Systems
