Protect Your Email from Spammers!

Nov 4, 2008 | Tags: Security | del.icio.us del.icio.us | digg Digg

One way the spammers got email addresses is, they collect email addresses from web pages. They use robots that crawl web pages and find any text like 'name@domain'.

To combat this email collector robots, make some small modifications to the emails you want to display. This will make the robots difficult to recognize your email addresses, but still readable by humans. For example, if your email is rahma.sarita@gmail.com, you might want to display it like this:

rahma.sarita @ gmail.com
rahma.sarita [at] gmail.com
rahma [dot] sarita [at] gmail [dot] com
rahma.sarixx@gmail.com

Here's the code:

Listing 1: listing-1.php

  1. <?php
  2. $email = "rahma.sarita@gmail.com";
  3.  
  4. /* sample 1 */
  5. $e1 = preg_replace("/@/", " @ ", $email);
  6.  
  7. /* sample 2 */
  8. $e2 = preg_replace("/@/", " [at] ", $email);
  9.  
  10. /* sample 3 */
  11. $e3 = preg_replace("/@/",  " [at] ",  $email);
  12. $e3 = preg_replace("/\./", " [dot] ", $e3);
  13.  
  14. /* sample 4 */
  15. list($u, $h) = explode("@", $email);
  16. $e4 = substr($u, 0, strlen($u)-2) . "xx@$h";
  17.  
  18. print "$email<br>"; /* rahma.sarita@gmail.com */
  19. print "$e1<br>";    /* rahma.sarita @ gmail.com */
  20. print "$e2<br>";    /* rahma.sarita [at] gmail.com */
  21. print "$e3<br>";    /* rahma [dot] sarita [at] gmail [dot] com */
  22. print "$e4<br>";    /* rahma.sarixx@gmail.com */
  23. ?>

Note that even this trick is useless if your mailto link still point to the original email address. Link to the modified one. Relax, a few lines of javascript will solve all problems.

Listing 2: page.html

  1. Send your email to:
  2. <a href="javascript:mailto('rahma.sarita [at] gmail.com')">
  3.   rahma.sarita [at] gmail.com
  4. </a>
  5.  
  6. <script language="javascript">
  7. function mailto(e)
  8. {
  9.     e = e.replace(/ /g, "");
  10.     e = e.replace(/\[at\]/, "@");
  11.     e = e.replace(/\[dot\]/g, ".");
  12.     document.location.href = "mailto:" + e;
  13. }
  14. </script>
  15.  

See, the javascript code above will 'fix' the email address and open up the user's email client program. Now for some demos:

Send your email to:
nashruddin.amin @ gmail.com
nashruddin.amin [at] gmail.com
nashruddin [dot] amin [at] gmail [dot] com

Done. This trick will save you from those spammers, at least the stupid one. :)

Related Articles

4 Comments

Your Missed Friend :) on May 22, 2008:

too difficult to understand
give me your private number please
-------
heri

Nash on May 22, 2008:

Ow, Is it too difficult?

Sorry I cannot post my private number here. Contact me [at] nashruddin.com.

Nadir on May 29, 2008:

Nice idea, but what if user hasn't JS enabled ?

Nash on May 30, 2008:

Then the user has to manually open the email program

Leave a comment

Name (required)
Email (will not be published) (required)
Website

Characters left = 1000

Tags

Recent Posts

  1. OpenCV Utility: Reading Image Pixels Value
  2. OpenCV Circular ROI
  3. OpenCV 2.0 Installation on Windows XP and Visual Studio 2008
  4. Runtime ROI Selection using Mouse
  5. Real Time Eye Tracking and Blink Detection
View Archives

About the Author

avatar Cool PHP programmer writing cool PHP scripts. Feel free to contact
Tel. +62 31 8662872
+62 856 338 6017
ICQ 489571630
Skype dede_bl4ckheart
Yahoo dede_bl4ckheart
Google nashruddin.amin

Recommended Sites:

Hacker's HTTP Client
HTML and CSS Tutorials
Stop Dreaming Start Action
Online Quran and Translation