Spam protect ‘mailto:’ links

Spam

Whilst working on this site I thought it best to protect my new e-mail address, as my previous mail account had a bit of spam and it was annoying – I’d like to keep this account as spam free as possible.

The standard e-mail link is:

Mail me

This poses an issue as spam-bots can scan your site, read this address, add it to their list and you’ll be forever getting those ‘down to your knee’ e-mails.

Some people like to just print their address in an obfuscated manner, ie. ‘Me(at)Domain(dot)com’, expecting visitors to interpret it and type it manually into their mail client. This is ok but I’m one for convenience – I like to just click on the link.

The solution? JavaScript and a bit of PHP for convenience. The PHP takes a few parameters and emits some Javascript to display the link. I’m not saying it’s 100% perfect but will certainly help:

<?php
function ProtectedEmail( $szAddress, $szServer, $szLink = '' )
{
?>

<?php
}
?>

*NOTE: You’ll need to delete lines 5 and 13 – they’re there to prevent the code being parsed within this post. To pass validation you may also need to use HTML comments (same as you’ve just deleted) around lines 7 and 8.

This code works by inserting broken-up javascript into your page instead of a complete link and should cause a headache for a lot of spam-bots. Call it as follows:

<?php
	ProtectedEmail( 'Me', 'Domain', '' );
?>

*NOTE: The image tag should be terminated with a slash ‘/>’ to be compliant but it’s been removed by the code syntax highlighter.

The 3rd parameter is optional and used if you wanted to display a button etc.. If it’s not used then the code will just display your e-mail address.

The PHP isn’t essential, you can just use the JavaScript from the function above in-place but I like to save my typing for things like this!

It’s possible to obfuscate the javascript a lot further, which I may do at some point, but that’s an exercise for another day.

Posted in Coding, Web | Tagged , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

> Talk to me!

Twitter profile for Richard Turnbullwitter:
  • Attempting to load Twitter feed..
Facebook profile for Richard Turnbull LinkedIn profile for Richard Turnbull

> Tools

Share |

> Advert