Problem using "%40" instead of "@" in mailto link

I had used the following code which was supposed to help stop e-mail collection & spam.

mailto:joe%40example%2ecom

Then someone said the link was not working with their iPad. So I reverted to plain old @ and .com to get it working.

Is this bad practice?
Why would their iPad not parse the html properly?
Is there another “easy” method to stop spam when a mailto link is necessary?

Appreciate any comments. :slight_smile:

If you use @, that should have the same effect as @. As far as I know, it should work on all devices, but I don’t have an iAnything so I can’t check it…

only in HTML - not in URLs and the mailto: on the front of the address indicates that it is supposed to be a URL rather than HTML.

Anyway with the mailto: there you may as well use @ since the mailto identifies it as an email address regardless of any obfuscation applied.

I put much thought into this a while back. There are three perfect ways to do this. Option one is preferred by me. In short you hide it with JS. But if JS is off plain text shows. Most the the css hiding ways don’t work as explained in the article. http://www.websitecodetutorials.com/code/javascript/graceful-degradation-mailto-email-address-obfuscation-tutorial.php

I don’t get any spam using this. Knowbody would.

Thanks Stevie D and felgall for your replies. Thanks Picnic for your link - that’s quite a comprehensive list! I like solution 2 and will try that next time I need. :slight_smile:

Why your just going to use the masked @? FYI that may trick 1 out of 20 bots.

Presumably the URL is supposed to be in an attribute value, where entities work fine and are perfectly allowed in all versions of HTML.

The %40 should also work in an attribute value that is allowed to contain a URL so that it isn’t working is an indication that it is not being used in an HTML attribute.

If you want to encode the HTML characters and still use a mailto link, you will also need to encode the “mailto:” as well. For some reason, you can’t mix the two.


function string_to_html_ascii($string)
{
    $ascii = NULL;
     
    for ($i = 0; $i < strlen($string); $i++)
    {
    $ascii.= '&#'.ord($string[$i]);
    }
     
    return($ascii);
}


$mailto_ascii='&#x6d;&#x61;il&#x74;o&#00058';

$email = string_to_html_ascii('name@example.org');

echo '<a href="'.$mailto_ascii.$email.'">email me</a>';


“mailto link” in the subject indicates otherwise.

That %40 isn’t working could just be a bug in the browser or the email app or the OS glue.