47
votes

When placing email addresses on a webpage do you place them as text like this:

[email protected]

or use a clever trick to try and fool the email address harvester bots? For example:

HTML Escape Characters:

joe.somebody@company.com

Javascript Decrypter:

function XOR_Crypt(EmailAddress)
{
    Result = new String();
    for (var i = 0; i < EmailAddress.length; i++)
    {
        Result += String.fromCharCode(EmailAddress.charCodeAt(i) ^ 128);
    }
    document.write(Result);
}

XOR_Crypt("êïå®óïíåâïäùÀãïíðáîù®ãïí");

Human Decode:

[email protected]

joe.somebody AT company.com

What do you use or do you even bother?

6
  • 17
    incidentally, you should always use example.com for a "sample" domain. See RFC-2606.
    – nsayer
    Oct 6, 2008 at 21:04
  • 6
    The best solution is not to share your solution. Unfortunately this is that sort of question. It's best to find your solution and keep it to yourself. If one gets standardized, spambots will be adapted to overcome it.
    – Dimitris
    Jun 12, 2014 at 15:28
  • 1
    The best solution is to combine several of the below solutions, e.g. first part of email as image, second part this.href.replace(/x/g,''), third part hex encoded, etc. No spam bot, no matter how clever, will try different methods of decoding on different parts of an email address.
    – user1322720
    Mar 26, 2015 at 9:18
  • Actually, you cannot really fool the bot! Just copy&paste your HTML escape characters to Google and see what I mean. I think the best way is to use a custom JavaScript.
    – katamayros
    Apr 3, 2015 at 11:12
  • I don't think the comment above about not sharing a solution is valid. You can share a solution and offer suggestions as to how to make it more difficult (e.g. instead of [at] replace with some other combination of characters). This would allow a solution to be shared and still not be automated, as each page would need to be analyzed, which a bot won't do. Jun 17, 2015 at 16:22

51 Answers 51

129
votes

Working with content and attr in CSS:

.cryptedmail:after {
  content: attr(data-name) "@" attr(data-domain) "." attr(data-tld); 
}
<a href="#" class="cryptedmail"
   data-name="info"
   data-domain="example"
   data-tld="org"
   onclick="window.location.href = 'mailto:' + this.dataset.name + '@' + this.dataset.domain + '.' + this.dataset.tld; return false;"></a>

When javascript is disabled, just the click event will not work, email is still displayed.

Another interesting approach (at least without a click event) would be to make use of the right-to-left mark to override the writing direction. more about this: https://en.wikipedia.org/wiki/Right-to-left_mark

4
  • 4
    Awesome. But append a ";return false" to the onclick-event. This will prevent the ugly addition of # to the browsers URL (by canceling the original href-link)
    – T4NK3R
    Apr 19, 2017 at 9:43
  • 10
    HOWEVER - I can't manually copy the (visible) mail-address (in either Chrome, Firefox or Edge) ?
    – T4NK3R
    Apr 19, 2017 at 9:52
  • @T4NK3R yes - it's an pseudo element, so you can't select it. you could implement a link for copy the mail to the clipboard. An workaround for yourself, at least in chrome, would be, to press ctrl+p for printing and select the e-mail in the preview.
    – cyptus
    Apr 19, 2017 at 13:40
  • I had accessibility concerns looking at this, but a quick research showed that current screen readers do read css generated content. An aria-label attribute that describes what will happen by clicking this link would still improve this, and since the href attribute does not describe the actual link target, a button element might be more appropriate and accessible. Also this might lead to fail this WCAG 2.0 test about "non-decorative content": w3.org/TR/WCAG20-TECHS/F87.html See also: adrianroselli.com/2019/02/…
    – makkabi
    Feb 24, 2020 at 19:15
97
votes

This is the method I used, with a server-side include, e.g. <!--#include file="emailObfuscator.include" --> where emailObfuscator.include contains the following:

<!-- // http://lists.evolt.org/archive/Week-of-Mon-20040202/154813.html -->
<script type="text/javascript">
    function gen_mail_to_link(lhs,rhs,subject) {
        document.write("<a href=\"mailto");
        document.write(":" + lhs + "@");
        document.write(rhs + "?subject=" + subject + "\">" + lhs + "@" + rhs + "<\/a>");
    }
</script>

To include an address, I use JavaScript:

<script type="text/javascript"> 
    gen_mail_to_link('john.doe','example.com','Feedback about your site...');
</script>
<noscript>
  <em>Email address protected by JavaScript. Activate JavaScript to see the email.</em>
</noscript>

Because I have been getting email via Gmail since 2005, spam is pretty much a non-issue. So, I can't speak of how effective this method is. You might want to read this study (although it's old) that produced this graph:

enter image description here

3
  • Why do you need server-side include of emailObfuscator.include? Wouldn't it be same just as writing it in plain .html? (perhaps it's just an example?) Also why do you use html comments <!-- --> inside script? And finally why one of your <script> tag is lowercase while others are uppercase <SCRIPT>? Do these methods help confuse bots or something?
    – Templar
    Jul 21, 2014 at 16:13
  • @Templar The SSI isn't necessary, nor does it confuse bots as far as I know. It makes (made) my site modular (don't really use this method anymore). The comment was citing the source of where I found the hack (now a broken link). The change in case is just a fluke. If it confuses bots, all the better, but I doubt it has any effect. Jul 21, 2014 at 21:09
  • 4
    A more recent and complete study exploring the same idea: grall.name/posts/1/antiSpam-emailAddressObfuscation.html Jul 6, 2017 at 11:43
90
votes

Have a look at this way, pretty clever and using css.

CSS

span.reverse {
  unicode-bidi: bidi-override;
  direction: rtl;
}

HTML

<span class="reverse">moc.rehtrebttam@retsambew</span>

The CSS above will then override the reading direction and present the text to the user in the correct order.

Hope it helps

Cheers

9
  • 61
    It's surely funny. But unfortunately, this is not clickable and won't work for copy/paste, while neglecting any non-CSS browser such as braille readers.
    – Arjan
    Jul 5, 2009 at 10:09
  • Mhh nice, but once people who write crawlers see it, it becomes useless.
    – Mau
    Aug 3, 2010 at 9:51
  • 6
    Matching reverse e-mail address with a RegEx is just as easy as matching it non-reversed. Spamming is a billion-dollar business and the spammer's aren't even using their own CPU cycles to scrape the screens. In fact, they have already read this conversation and have adjusted their methods accordingly. Anything computer readable is going to be readable by the bots. Whether it be executed by CSS or JavaScript. Aug 24, 2013 at 11:54
  • 3
    @JaniHyytiäinen I disagree. The fact they are not paying for the CPU, does not mean they have unlimited resources. If running a JS interpreter turns out to yield too few addresses for its cost, they'll disable it.
    – o0'.
    Feb 23, 2015 at 11:32
  • 1
    @Lohoris: Google reports average page load time being (2.45s) and average page size (320KB), it gives you an idea how much parsing you can do. While a downloading thread is doing the requests, a parsing thread can do the parsing. Majority of downloading is waiting. Which gives the dl thread the possibility of checking prerequisites before deciding to send it to parser. E.g. rendering page, indexOf('@'), indexOf('mailto:'), etc. The parsing thread would receive only +-200 chars around the match which would allow so complex parsing that it would 'appear' to be infinite in terms of parsing power. Feb 28, 2015 at 8:33
52
votes

Not my idea originally but I can't find the author:

<a href="mailto:[email protected]"
    onmouseover="this.href=this.href.replace(/x/g,'');">link</a>

Add as many x's as you like. It works perfectly to read, copy and paste, and can't be read by a bot.

8
  • 2
    Neat! But what about mobile users?
    – Bodzio
    Jul 13, 2015 at 19:51
  • Mouseovers are also triggered when you touch a link. It should work fine.
    – Andy Swift
    Jul 16, 2015 at 14:36
  • 4
    Works as long as your address doesn't contain any x's. :-p But, I know, just use a different letter. Oct 7, 2015 at 19:27
  • 1
    But then If javascript is disabled you are presenting users with nonexisting address that will bounce back loosing you a customer/user.
    – Xeevis
    Jan 3, 2016 at 19:24
  • 41
    If javascript is disabled, none of my sites works at all ;-)
    – Andy Swift
    Jan 13, 2016 at 16:25
45
votes

I generally don't bother. I used to be on a mailing list that got several thousand spams every day. Our spam filter (spamassassin) let maybe 1 or 2 a day through. With filters this good, why make it difficult for legitimate people to contact you?

1
  • 2
    So you don't need brakes in a car, because you have an air-bag which protects you? :-D Sorry about that joke, but I think to reduce the worldwide spam you should try at least to make it harder for bots to read the e-mail address.
    – zypro
    Dec 6, 2018 at 15:08
27
votes

Invent your own crazy email address obfuscation scheme. Doesn't matter what it is, really, as long as it's not too similar to any of the commonly known methods.

The problem is that there really isn't a good solution to this, they're all either relatively simple to bypass, or rather irritating for the user. If any one method becomes prevalent, then someone will find a way around it.

So rather than looking for the One True email address obfuscation technique, come up with your own. Count on the fact that these bot authors don't care enough about your site to sit around writing a thing to bypass your slightly crazy rendering-text-with-css-and-element-borders or your completely bizarre, easily-cracked javascript encryption. It doesn't matter if it's trivial, nobody will bother trying to bypass it just so they can spam you.

0
16
votes

I think the only foolproof method you can have is creating a Contact Me page that is a form that submits to a script that sends to your email address. That way, your address is never exposed to the public at all. This may be undesirable for some reason, but I think it's a pretty good solution. It often irks me when I'm forced to copy/paste someone's email address from their site to my mail client and send them a message; I'd rather do it right through a form on their site. Also, this approach allows you to have anonymous comments sent to you, etc. Just be sure to protect your form using some kind of anti-bot scheme, such as a captcha. There are plenty of them discussed here on SO.

6
  • 6
    The only problem with this is that you don't have a copy of the message you sent unless you take the time to copy and paste it somewhere else. Personally I don't mind copy and paste but to each their own.
    – gvkv
    Jun 13, 2009 at 19:58
  • 6
    As for the sender not having a copy: for many kind of forms on the web I love the option to get a copy myself. However, often such an option allows for abuse for anonymously sending messages to just about anyone...
    – Arjan
    Jul 5, 2009 at 10:12
  • 12
    This may HIDE your email address, but it wont stop the spam at all, unless you secure your form with a captcha image validation script. Aug 3, 2010 at 9:33
  • 1
    You can also solve the problem of the sender not having a copy by including an option to send it to them as well.
    – steinybot
    Jun 11, 2013 at 11:00
  • 1
    The option "Send a copy to yourself" - effectively turns the form into a spam-canon, with you as the sender - bad idea!
    – T4NK3R
    Apr 19, 2017 at 10:39
16
votes

You can protect your email address with reCAPTCHA, they offer a free service so people have to enter a CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) to see your email: https://www.google.com/recaptcha/admin#mailhide

3
  • CAPTCHA is not a 100% reliable solution. See e.g., blackhat-seo.com/2009/captcha-farms
    – mouviciel
    Nov 6, 2009 at 12:27
  • 8
    Part of the point is to make it convenient to viewers to get email addresses ... how is this "easy"?
    – Robert K
    Nov 6, 2009 at 12:51
  • i found it easy to hack this but requires minimal human interaction, so imagine thousands of people just solving captchas the whole day. Thats also the reason why it costs money
    – john Smith
    Oct 29, 2016 at 10:24
16
votes

I've written an encoder (source) that uses all kinds of parsing tricks that I could think of (different kinds of HTML entities, URL encoding, comments, multiline attributes, soft hyphens, non-obvious structure of mailto: URL, etc)

It doesn't stop all harvesters, but OTOH it's completely standards-compliant and transparent to the users.

Another IMHO good approach (which you can use in addition to tricky encoding) is along lines of:

<a href="mailto:[email protected]" 
   onclick="this.href=this.href.replace(/hatestogetspam/,'')">
1
  • I like the idea of the second approach, except that when you hover over the link it displays the masked address, so make sure you don't use a swear word for the replacement word ;) Oct 19, 2011 at 20:58
11
votes

If you have php support, you can do something like this:

<img src="scriptname.php">

And the scriptname.php:

<?php
header("Content-type: image/png");
// Your email address which will be shown in the image
$email    =    "[email protected]";
$length    =    (strlen($email)*8);
$im = @ImageCreate ($length, 20)
     or die ("Kann keinen neuen GD-Bild-Stream erzeugen");
$background_color = ImageColorAllocate ($im, 255, 255, 255); // White: 255,255,255
$text_color = ImageColorAllocate ($im, 55, 103, 122);
imagestring($im, 3,5,2,$email, $text_color);
imagepng ($im);
?>
1
  • 1
    rather than using php you could physically create the image. And as with the css invert you still have the problem of not being clickable and can't be copied unless using a pen :P
    – Claudiu
    Mar 26, 2015 at 17:17
9
votes

I know my answer won't be liked by many but please consider the points outlined here before thumbing down.

Anything easily machine readable will be easily machine readable by the spammers. Even though their actions seem stupid to us, they're not stupid people. They're innovative and resourceful. They do not just use bots to harvest e-mails, they have a plethora of methods at their disposal and in addition to that, they simply pay for good fresh lists of e-mails. What it means is, that they got thousands of black-hat hackers worldwide to execute their jobs. People ready to code malware that scrape the screens of other peoples' browsers which eventually renders any method you're trying to achieve useless. This thread has already been read by 10+ such people and they're laughing at us. Some of them may be even bored to tears to find out we cannot put up a new challenge to them.

Keep in mind that you're not eventually trying to save your time but the time of others. Because of this, please consider spending some extra time here. There is no easy-to-execute magic bullet that would work. If you work in a company that publishes 100 peoples' e-mails on the site and you can reduce 1 spam e-mail per day per person, we're talking about 36500 spam emails a year. If deleting such e-mail takes 5 seconds on average, we're talking about 50 working hours yearly. Not to mention the reduced amount of annoyance. So, why not spend a few hours on this?

It's not only you and the people who receive the e-mail that consider time an asset. Therefore, you must find a way to obfuscate the e-mail addresses in such way, that it doesn't pay off to crack it. If you use some widely used method to obfuscate the e-mails, it really pays off to crack it. Since as an result, the cracker will get their hands on thousands, if not tens or hundreds of thousands of fresh e-mails. And for them, they will get money.

So, go ahead and code your own method. This is a rare case where reinventing the wheel really pays off. Use a method that is not machine readable and one which will preferably require some user interaction without sacrificing the user experience.

I spent some 20 minutes to code off an example of what I mean. In the example, I used KnockoutJS simply because I like it and I know you won't probably use it yourself. But it's irrelevant anyway. It's a custom solution which is not widely used. Cracking it won't pose a reward for doing it since the method of doing it would only work on a single page in the vast internet.

Here's the fiddle: http://jsfiddle.net/hzaw6/

The below code is not meant to be an example of good code. But just a quick sample of code which is very hard for machine to figure out we even handle e-mails in here. And even if it could be done, it's not gonna pay off to execute in large scale.

And yes, I do know it doesn't work on IE = lte8 because of 'Unable to get property 'attributes' of undefined or null reference' but I simply don't care because it's just a demo of method, not actual implementation, and not intended to be used on production as it is. Feel free to code your own which is cooler, technically more solid etc..

Oh, and never ever ever name something mail or email in html or javascript. It's just way too easy to scrape the DOM and the window object for anything named mail or email and check if it contains something that matches an e-mail. This is why you don't want any variables ever that would contain e-mail in it's full form and this is also why you want user to interact with the page before you assign such variables. If your javascript object model contains any e-mail addresses on DOM ready state, you're exposing them to the spammers.

The HTML:

<div data-bind="foreach: contacts">
    <div class="contact">
        <div>
            <h5 data-bind="text: firstName + ' ' + lastName + ' / ' + department"></h5>
            <ul>
                <li>Phone: <span data-bind="text: phone"></span></li>
                <li><a href="#999" data-bind="click:$root.reveal">E-mail</a> <span data-bind="visible: $root.msgMeToThis() != ''"><input class="merged" data-bind="value: mPrefix" readonly="readonly" /><span data-bind="text: '@' + domain"></span></span></li>
            </ul>
        </div>
    </div>
</div>

The JS

function ViewModel(){
    var self = this;

    self.contacts = ko.observableArray([
        { firstName:'John', mPrefix: 'john.doe', domain: 'domain.com', lastName: 'Doe', department: 'Sales', phone: '+358 12 345 6789' },
        { firstName:'Joe', mPrefix: 'joe.w', domain: 'wonder.com', lastName: 'Wonder', department: 'Time wasting', phone: '+358 98 765 4321' },
        { firstName:'Mike', mPrefix: 'yo', domain: 'rappin.com', lastName: 'Rophone', department: 'Audio', phone: '+358 11 222 3333' }
    ]);
    self.msgMeToThis = ko.observable('');
    self.reveal = function(m, e){
        var name = e.target.attributes.href.value;
        name = name.replace('#', '');
        self.msgMeToThis(name);
    };
}
var viewModel = new ViewModel();
ko.applyBindings(viewModel);
8
votes

You can try to hide characters using html entities in hexa (ex: &#x40 for @). This is convenient solution, as a correct browser will translate it, and you can have a normal link. The drawback is that a bot can translate it theorically, but it's a bit unusual. I use this to protect my e-mail on my blog.

Another solution is to use javascript to assemble part of the address and to decode on-the-fly the address. The drawback is that a javascript-disabled browser won't show your adress.

The most effective solution is to use an image, but it's a pain for the user to have to copy the address by hand.

Your solution is pretty good, as you only add a drawback (writing manually the @) only for user that have javascript disabled. You can also be more secure with :

onclick="this.href='mailto:' + 'admin' + '&#x40;' + 'domain.com'"
8
votes

One of my favorite methods is to obfuscate the email address using php, a classic example is to convert the characters to HEX values like so:

function myobfiscate($emailaddress){
 $email= $emailaddress;                
 $length = strlen($email);                         
 for ($i = 0; $i < $length; $i++){                
 $obfuscatedEmail .= "&#" . ord($email[$i]).";";
 }
 echo $obfuscatedEmail;
}

And then in my markup I'll simply call it as follows:

  <a href="mailto:<?php echo myobfiscate('[email protected]'); ?>"
title="Email me!"><?php echo myobfiscate('[email protected]');?> </a>

Then examine your source, you'll be pleasantly surprised!

0
6
votes

I wouldn't bother -- it is fighting the SPAM war at the wrong level. Particularly for company web sites I think it makes things look very unprofessional if you have anything other than the straight text on the page with a mailto hyperlink.

There is so much spam flying around that you need good filtering anyway, and any bot is going end up understanding all the common tricks anyway.

2
  • This thing about a bot understanding the common tricks is wrong. AFAIK, spammers generally don't try any OCR or javascript evaluation, becuase they don't really need to. Oct 2, 2008 at 17:58
  • I agree with your comment about company web sites not having anything other than a straight mailto: link, but those links should always go to role addresses like "sales@" or "info@" or what not. Those addresses will be less valuable to spammers anyway. Things are different for personal pages.
    – nsayer
    Oct 2, 2008 at 18:10
6
votes

HTML:

<a href="#" class="--mailto--john--domain--com-- other classes goes here" />

JavaScript, using jQuery:

// match all a-elements with "--mailto--" somehere in the class property
$("a[class*='--mailto--']").each(function ()
{
    /*
    for each of those elements use a regular expression to pull
    out the data you need to construct a valid e-mail adress
    */
    var validEmailAdress = this.className.match();

    $(this).click(function ()
    {
        window.location = validEmailAdress;
    });
});
0
5
votes

Spambots won't interpret this, because it is a lesser-known method :)

First, define the css:

email:before {
    content: "admin";
}

email:after {
    content: "@example.com";
}

Now, wherever you want to display your email, simply insert the following HTML:

<div id="email"></div>

And tada!

2
  • 1
    This works, but it does not support copy paste, which may affect usability for most users Feb 13, 2020 at 7:19
  • 1
    Identical to other already-existing top answers
    – vsync
    Oct 3, 2021 at 7:19
4
votes

I use a very simple combination of CSS and jQuery which displays the email address correctly to the user and also works when the anchor is clicked or hovered:

HTML:

<a href="mailto:[email protected]" id="lnkMail">moc.elpmaxe@em</a>

CSS:

#lnkMail {
    unicode-bidi: bidi-override;
    direction: rtl;
}

jQuery:

$('#lnkMail').hover(function(){
    // here you can use whatever replace you want
    var newHref = $(this).attr('href').replace('spam', 'com');
    $(this).attr('href', newHref);
});

Here is a working example.

4
  • will it show the correct value of href in the browser status bar when the link is hovered over?
    – Nik O'Lai
    Jun 18, 2015 at 18:51
  • Yes, it does show the correct value of href when the link is hovered. That's why the jQuery method .hover needs to be implemented.
    – Sergiu
    Jun 22, 2015 at 6:57
  • Unfortunately, no, it does not show the correct value of href, at least, when you hover over the link the first time (it is [email protected]). On the second hover everything was ok. Test it with your own link.
    – Nik O'Lai
    Jul 3, 2015 at 14:52
  • 1
    It's working in Chrome and IE. Seems like only on Firefox, on first hover, the status bar is not updated. I'll try to find a solution for Firefox.
    – Sergiu
    Jul 6, 2015 at 6:53
3
votes

I don't bother. You'll only annoy sophisticated users and confuse unsophisticated users. As others have said, Gmail provides very effective spam filters for a personal/small business domain, and corporate filters are generally also very good.

3
votes

The best method hiding email addresses is only good until bot programmer discover this "encoding" and implement a decryption algorithm.

The JavaScript option won't work long, because there are a lot of crawler interpreting JavaScript.

There's no answer, imho.

4
  • Are there crawlers interpreting JavaScript? My one JavaScript encoding method has seemed to work well for me over the past few years--my spam rate has been a fairly steady ~4/week, so I haven't worried about other people's addresses that I entrusted to this method. Should I?
    – Kev
    Jan 27, 2009 at 13:46
  • For sure, it may exclude lots of crawlers, but me, if I created an address crawler, I would implement a JavaScript lib :)
    – guerda
    Jan 28, 2009 at 14:17
  • more effort than you might think
    – user47322
    Jun 13, 2009 at 12:03
  • Google is crawling through some JS now. Jun 13, 2009 at 12:38
3
votes

!- Adding this for reference, don't know how outdated the information might be, but it tells about a few simple solutions that don't require the use of any scripting

After searching for this myself i came across this page but also these pages:

http://nadeausoftware.com/articles/2007/05/stop_spammer_email_harvesters_obfuscating_email_addresses

try reversing the emailadress

Example plain HTML:

<bdo dir="rtl">moc.elpmaxe@nosrep</bdo>
Result : [email protected]

The same effect using CSS

CSS:
.reverse { unicode-bidi:bidi-override; direction:rtl; }
HTML:
<span class="reverse">moc.elpmaxe@nosrep</span>
Result : [email protected]

Combining this with any of earlier mentioned methods may even make it more effective

3
votes

One easy solution is to use HTML entities instead of actual characters. For example, the "[email protected]" will be converted into :

<a href="&#109;&#97;&#105;&#108;&#116;&#111;&#58;&#109;&#101;&#64;&#101;&#120;&#97;&#109;&#112;&#108;&#101;&#46;&#99;&#111;&#109;">email me</A>
6
3
votes

A response of mine on a similar question:

I use a very simple combination of CSS and jQuery which displays the email address correctly to the user and also works when the anchor is clicked:

HTML:

<a href="mailto:[email protected]" id="lnkMail">moc.elpmaxe@em</a>

CSS:

#lnkMail {
  unicode-bidi: bidi-override;
  direction: rtl;
}

jQuery:

$('#lnkMail').hover(function(){
  // here you can use whatever replace you want
  var newHref = $(this).attr('href').replace('spam', 'com');
  $(this).attr('href', newHref);
});

Here is a working example.

3
votes

Here is my working version:


Create somewhere a container with a fallback text:

<div id="knock_knock">Activate JavaScript, please.</div>

And add at the bottom of the DOM (w.r.t. the rendering) the following snippet:

<script>
  (function(d,id,lhs,rhs){
    d.getElementById(id).innerHTML = "<a rel=\"nofollow\" href=\"mailto"+":"+lhs+"@"+rhs+"\">"+"Mail"+"<\/a>";
  })(window.document, "knock_knock", "your.name", "example.com");
</script>

It adds the generated hyperlink to the specified container:

<div id="knock_knock"><a rel="nofollow" href="[email protected]">Mail</a></div>

In addition here is a minified version:

<script>(function(d,i,l,r){d.getElementById(i).innerHTML="<a rel=\"nofollow\" href=\"mailto"+":"+l+"@"+r+"\">"+"Mail"+"<\/a>";})(window.document,"knock_knock","your.name","example.com");</script>
3
votes

A neat trick is to have a div with the word Contact and reveal the email address only when the user moves the mouse over it. E-mail can be Base64-encoded for extra protection.

Here's how:

<div id="contacts">Contacts</div>

<script>
  document.querySelector("#contacts").addEventListener("mouseover", (event) => {
    // Base64-encode your email and provide it as argument to atob()
    event.target.textContent = atob('aW5mb0BjbGV2ZXJpbmcuZWU=')
  });
</script>
2
votes

The only safest way is of course not to put the email address onto web page in the first place.

2
  • Yes. If you want to really_hide your email address, put a captcha-protected form on the webpage which sends email to you in the background (without displaying the address in the GUI, of course).
    – gabr
    Oct 4, 2008 at 14:41
  • 3
    Very true, except that in some countries it is required by law. Germany is an example. May 11, 2009 at 21:56
2
votes

Use a contact form instead. Put all of your email addresses into a database and create an HTML form (subject, body, from ...) that submits the contents of the email that the user fills out in the form (along with an id or name that is used to lookup that person's email address in your database) to a server side script that then sends an email to the specified person. At no time is the email address exposed. You will probably want to implement some form of CAPTCHA to deter spambots as well.

1
  • CAPTCHA will be pretty annoying, probably more than e-mail address obfuscation.
    – Kornel
    Nov 17, 2008 at 21:03
2
votes

There are probably bots that recognize the [at] and other disguises as @ symbol. So this is not a really effective method.

Sure you could use some encodings like URL encode or HTML character references (or both):

// PHP example
// encodes every character using URL encoding (%hh)
function foo($str) {
    $retVal = '';
    $length = strlen($str);
    for ($i=0; $i<$length; $i++) $retVal.=sprintf('%%%X', ord($str[$i]));
    return $retVal;
}
// encodes every character into HTML character references (&#xhh;)
function bar($str) {
    $retVal = '';
    $length = strlen($str);
    for ($i=0; $i<$length; $i++) $retVal.=sprintf('&#x%X;', ord($str[$i]));
    return $retVal;
}

$email = '[email protected]';
echo '<a href="'.bar('mailto:?to=' . foo(','.$email.'')).'">mail me</a>';

// output
// <a href="&#x6D;&#x61;&#x69;&#x6C;&#x74;&#x6F;&#x3A;&#x3F;&#x74;&#x6F;&#x3D;&#x25;&#x32;&#x43;&#x25;&#x37;&#x35;&#x25;&#x37;&#x33;&#x25;&#x36;&#x35;&#x25;&#x37;&#x32;&#x25;&#x34;&#x30;&#x25;&#x36;&#x35;&#x25;&#x37;&#x38;&#x25;&#x36;&#x31;&#x25;&#x36;&#x44;&#x25;&#x37;&#x30;&#x25;&#x36;&#x43;&#x25;&#x36;&#x35;&#x25;&#x32;&#x45;&#x25;&#x36;&#x33;&#x25;&#x36;&#x46;&#x25;&#x36;&#x44;">mail me</a>

But as it is legal to use them, every browser/e-mail client should handle these encodings too.

2
  • Totally agree, spammers are "clever" people, after years of people adding [at] or [dot] in place of the syntax, of course they're going to have algorithms that pick these patterns up. Aug 3, 2010 at 9:35
  • What about decoding these HEX values? Apr 4, 2012 at 22:31
2
votes

One possibility would be to use isTrusted property (Javascript).

The isTrusted read-only property of the Event interface is a Boolean that is true when the event was generated by a user action, and false when the event was created or modified by a script or dispatched via EventTarget.dispatchEvent().

eg in your case:

getEmail() {
  if (event.isTrusted) {
    /* The event is trusted */
    return '[email protected]';
  } else {
    /* The event is not trusted */
    return '[email protected]';
  }
}

⚠ IE isn't compatible !

Read more from doc: https://developer.mozilla.org/en-US/docs/Web/API/Event/isTrusted

1
vote

I make mine [email protected] and then next to it I write "Remove the capital letters"

2
  • This is so common and obvious that harvesters probably already do that.
    – Kornel
    Nov 17, 2008 at 21:04
  • You could write [email protected] and tell them, remove the "dog" :)
    – Avatar
    Nov 15, 2013 at 7:45
1
vote

Another, possibly unique, technique might be to use multiple images and a few plain-text letters to display the address. That might confuse the bots.

Not the answer you're looking for? Browse other questions tagged or ask your own question.