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%

Via this simple invocation:

<? echo mail_obfuscate($email);?>

Not exactly a new trick, but very useful indeed!