Email Link Obfuscator

This PHP function / jQuery plugin will create an obfuscated mailto link that will protect your email addresses from the spam bots that harvest the web. This is accomplished by:

  • Base64 encoding the entire href mailto link
  • Putting the encoded link into the anchor's title
  • Placing an innocent looking, do nothing "#" into the href
  • Giving the anchor a class of "nospam"
  • Calling the jQuery nospam function on all of the "nospam" anchor tags
  • When a user hovers over the "nospam" link, the title is Base64 decoded
  • The href "#" is then replaced with the unobfuscated mailto parameters
  • The user clicks on the link and is able to send their email
  • When the mouse leaves the anchor area, then the link turns back into it's obfuscated self

string email_link ( string $text, string $to [, string $subject [, string $body ]] )

This function will create an obfuscated mailto link that is only decoded when an actual user hovers over the link with their mouse and clicks on it.

$text The anchor text.
$to The email address.
$subject The email's subject.
$body The email's body. This can include <br /> tags and newlines.
Returns Your obfuscated email link.
$html .= email_link('Spam me please', '', 'faster cheaper meds', "Hello friend,\n\nWe are please to offer...");
Click to Download the PHP Email Link Obfuscator Function

 Subscribe to our feed

comments powered by Disqus
Copyright © 2012 - PHP Made Easy