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 Article

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

Newsletter

Send me your new post on:
OpenCV
PHP
Projects
Networking
Regex
to my email:
No, I won't spam your email.

Recent Posts

  1. PHP Script for Converting Relative to Absolute URL
  2. Streaming OpenCV Videos Over the Network
  3. Password Protected Images with PHP
  4. OpenCV Region of Interest (ROI)
  5. Web Based Surveillance System with OpenCV, PHP and Javascript

Popular Posts

  1. OpenCV Eye Detection
  2. OpenCV Examples Part 1
  3. OpenCV Face Detection
  4. OpenCV Eye Tracking
  5. Display Video from Webcam
  6. Phase Correlation in OpenCV
  7. Simple File Server and Downloader Script
  8. Building Dynamic SQL String from Associative Array
  9. Template Matching with OpenCV
  10. Fetching a Web Page From Your PHP Code

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