How to obfuscate your email address from spam bots using PHP
Posted: Sun Nov 29, 2009 3:45 am
Want to have an email address on your web page but don't want the bots to harvest it for their spam lists? Try this technique.
Put this JavaScript in the <head> of your html page:
Then use this as your email link:
If you only use one domain name for all your email addresses on the page, then you can obfuscate further by hard coding the domain name in the JavaScript function and take it out of the link. See the example below:
You can autocomplete the subject and even include text in the body of the new email. Simply include ?subject= which can be followed by &body= as shown in the following example. Note that use of some special characters can cause this not to work.
Put this JavaScript in the <head> of your html page:
Code: Select all
<script type="text/javascript">
function contact(domain,user) {
window.location.href = "mailto:" + user + "@" + domain;
}
</script>
Code: Select all
<a href="javascript:contact('example.com','name');">Contact Us</a>
Code: Select all
<script type="text/javascript">
function contact(user) {
window.location.href = "mailto:" + user + "@example.com";
}
</script>
<a href="javascript:contact('name');">Contact Us</a>
Code: Select all
window.location.href = "mailto:" + user + "@" + domain + "?subject=This is the subject line&body=This is some body text";