Obfuscate your email in webpage


If you have blog or website where you placed your email address, you may notice that there might be many spam emails send to your email address. This is because spammer scour the web to harvest email addresses. So to prevent this problem you can use obfuscated email address. Here I am showing a simple hack to solve this problem.

<?php
     $link = 'mailto:' . 'awoman@gmail.com';
     $coded = "";
     for ($i=0; $i<strlen($link); $i++){
         $coded .= "&#" . ord($link[$i]) . ";";
     }
?>

<a href="<?=$coded?>">Email Awoman</a>

In browser normal user will show simple html link like: Email Awoman but if you see the view source you ‘ll see

<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#97;&#119;&#111;&#109;&#97;&#110;&#64;&#103;&#109;&#97;&#105;&#108;&#46;&#99;&#111;&#109;">Email Awoman</a>

The code is very simple. Using email address, create a mailto link and then loop though the characters by replacing each character with ASCII equivalent.

mahmud ahsan

Love computer programming and write occasional blog post. In my early career I worked mostly on web based application and since 2011, I exclusively working on iPhone and android applications. I work at home, father of a nice kid and husband of a beautiful wife. [My Business | Twitter | Linkedin]

You may also like

1 Comment

  • Rajesh
    August 14, 2013 at 4:24 pm

    this is not working even in ur example above 🙁

Comments are closed here.

About Me

Hi I am Mahmud Ahsan. I Love computer programming and write occasional blog post. In my early career I worked mostly on web based application and since 2011, I exclusively working on iPhone and android applications. I work at home, father of a nice kid and husband of a beautiful wife. [My Business | Twitter | Linkedin]

Twitter Feed

Fanpage