Is there an elegant and easy/simple way to do it using PHP, Javascript or Jquery?
11 Answers
There are many ways of doing this. We've had som luck obfuscating source via python/javascript. Another simpler favourite is the CSS unicode-bidi technique:
div.contact { unicode-bidi:bidi-override; direction: rtl; }
<div class="contact">moc.rab@oof</div>
Prints out:
foo@bar.com

- 106,495
- 44
- 176
- 212
-
But how can I reverse the email address using PHP or JS? – Steven Dec 09 '09 at 14:04
-
I'm not a PHP guy, but try the strrev() method: http://php.net/manual/en/function.strrev.php – David Hellsing Dec 09 '09 at 14:09
-
..this has just 1 problem, if someone try to copy'n'paste the email adress, he will see the reversed version, "moc.rab@oof" – Strae Dec 09 '09 at 14:39
-
as I commented below, any javascript manipulation will be defeated by robots doing full DOM render. You're best of with an image, or the recaptcha solution suggested here. – Richard H Dec 09 '09 at 19:34
You might want to look into reCAPTCHA Mailhide. It should be easy to use from PHP.

- 31,109
- 6
- 81
- 98
-
this looks to be one of the best solutions i've seen. however, it does come with the cost of being a slight pain for the user – Richard H Dec 09 '09 at 19:32
-
@Richard. Yes, for the users who will actually use the address, that is :) – jensgram Dec 10 '09 at 08:02
You can use the PHP imagestring() function to create an image.
<?php
// Create a 100*30 image
$im = imagecreate(120, 30);
// White background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
// Write the email address at the top left
imagestring($im, 5, 0, 0, 'test@test.com', $textcolor);
// Output the image
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>

- 3,374
- 10
- 40
- 48
-
-
..save the image on the web server, and load it in the html page simply with
– Strae Dec 09 '09 at 14:49
Obfuscation using trickiest possible HTML entities and urlencode, implemented in PHP: http://hcard.geekhood.net/encode/
Source: http://code.google.com/p/hcardvalidator/source/browse/trunk/encode/index.php
Another approach I use is:
<a href="mailto:me@myserver.removethis.com">
<script>[…] a.href = a.href.replace(/removethis\./,'');</script>
It's worth noting that both techniques give users perfectly accessible, clickable link.

- 97,764
- 37
- 219
- 309
never write email addresses as text on webpages, NEVER!
and browser bots surely have JS enabled -_-
-
Maybe you dont believe, but many costumer want the emails to be ritten in the HTML, in text form. I warn them about the spam, but they simply dont care... well, the take care of it just 3 months later ;) – Strae Dec 09 '09 at 14:25
you can try changing name@example.com to: "name at example dot com".
However, robots can easily account for this.
Otherwise, you could display a dynamic image of the email address if you are truly motivated.

- 12,072
- 9
- 51
- 69
It's not a perfect solution, but the Enkoder (http://hivelogic.com/enkoder) is quite useful for this. It uses Javascript to obfuscate the address.

- 6,338
- 25
- 23
Ok. So after a while, I've found this blog article on how to do this easily. http://techblog.tilllate.com/2008/07/20/ten-methods-to-obfuscate-e-mail-addresses-compared/ And how much impact does it do on spam receiving ..
I guess this could be complementary to the info given above .. Cheers!

- 618
- 1
- 9
- 17
Would this work as well??
Using something like this
<span>myaddress</span><span>@</span><span>mydomain.com</span>
This won't stand as a link, but would still be recognizable by the human eye on a page, and probably con't be parsed by a robot. Haven't checked it out, thou. You could probably insert that string into a void and bind it to a function that composes the address by parsing out the content ..
Just a fast thought ...

- 618
- 1
- 9
- 17
-
this would be picked up by any robot doing the minimum of DOM parsing – Richard H Dec 09 '09 at 19:28
This is difficult to do. Unless you use an image, anything which is rendered human-readable by your browser can be rendered human-readable by a robot. So even scrambling the e-email in some way in the HTML source and then using a javascript function to de-scramble dynamically on page rendering, this will be defeated by a robot which also does full rendering of the DOM.
Until recently I had good success with the above method, and didn't see any spam. Recently however I have noticed that addresses do seem to have been picked up. So I can only assume e-mail trawlers are now doing full DOM rendering.
So to conclude - an image is probably best (although even that is not 100%)

- 38,037
- 37
- 111
- 138
Here is a simple jquery solution to this problem:
<script type="text/javascript">
$(document).ready(function() {
str1="mailto:";
str2="info";
str3="@test.com";
$("#email_a").attr("href", str1+str2+str3);
});
</script>
<a href="#" id="email_a"><img src="sample.png"/></a>

- 2,091
- 2
- 27
- 35