Obfuscate e-mails in PHP

Exactly one year ago, I was complaining to one of my clients ISP about the increasing volume of spam those people were receiving lately. The ISP answered me with some not particularly useful advices, except for one: they had inspected my client's website and had found that the contacts section had a list of clean e-mail addresses, happily standing there to the delight of some spammer's spider bot. I had put them there in the good-old format mailto:dontphunk@withmyheart.com, and the ISP adviced me to substitute the text with images, which I found weird, even more considering that all those e-mail addresses were generated dynamically.

So I didn't consider the advice then (shame on me), but as I was yesterday making some changes to the website after a long time I stepped again with the e-mail, and decided to finally take some actions. Enter Aidan's mail_obfuscate PHP function, an easy way to convert typical mailto:been@there.com addresses into something ehmm... more obscure:

<script language="javascript">eval(unescape('%64%6f%63%75%6d%65%6e%
74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22
%6d%61%69%6c%74%6f%3a%6d%61%67%75%69%6c%61%72%40%6e%6f
%76%61%62%61%64%69%61%2e%6e%65%74%22%3e%6d%61%67%75%69
%6c%61%72%40%6e%6f%76%61%62%61%64%69%61%2e%6e%65%74%3c
%2f%61%3e%27%29%3b'))</script>

Via this simple invocation:

<? echo mail_obfuscate($email);?>

Not exactly a new trick, but very useful indeed!