简体   繁体   中英

Hide Mailto: link

I have varying mailto: email address on my site which are now being hit with various harvesters and subsequently I'm being spammed.

Can anyone assist me in creating some PHP code for the following:

<a href="mailto:info@company.com">info@company.com</a>

To prevent the address from being harvested and equally can I use this script on various email address displayed on the site?

Thanks

Others have suggested writing the e-mail address using JavaScript's document.write() . I don't like this approach because it's easily defeated by bots that bother actually rendering the page. I have received spam on e-mail addresses "protected" this way (not as much and not as quickly as unprotected addresses, but still it comes).

My preferred approach is to write the link using a dummy e-mail address (which can go to a honeypot e-mail address on your mail server, so you can determine which server IP addresses to blacklist). Then use an onClick handler on the link to substitute in the real e-mail address when the user clicks it. No e-mail harvester is going to send a click event to every link on a page, it just wouldn't work.

<a href="mailto:fake@example.com" 
   onClick="this.href=this.href.replace('fake', 'real')">
Send Us E-mail</a>

In this example we start with "fake@example.com" and replace "fake" with "real" when the user clicks the link.

Another idea I like is to have the user enter their e-mail address into a form. Then you send them an e-mail using a script. They reply to that e-mail address to initiate contact with you. In other words, they don't get your e-mail address until they give you a valid one of their own, and your address is never on the site.

The best solution that I've found is to use a bit of javascript. You call a function, passing in the address, and it will print out the link for you. Since most bots don't process javascript, this should work for a majority of cases:

<script type='text/javascript'>
    function email(name, domain, withlink) {
        var addr = name + '@' + domain;
        if(withlink) {
            document.write('<a href="mailto:' + addr + '">' + addr + '</a>');
        } else {
            document.write(addr);
        }
    }
</script>

And then, when you want to print an email address on the site:

<script>email('myuser', 'mydomain');</script>

If you want it to make it a clickable link:

<script>email('myuser', 'mydomain', true);</script>

Note: This is untested, but it should work. There are also more advanced techniques, which some of the other answers touch on, but most of them build off of a base like this.

I would do it in Javascript. Try something like

<script>
document.write('<a href="mailto:inblahfo@company.com">inblahfo@company.com</a>'
.replace(/blah/g, ''));
</script>

I've always liked the Hive Enkoder to create mailto links:

http://hivelogic.com/enkoder/

I would do it this way:

function obfuscate_email($email) {
    $obf = '';
    for($i = 0; $i < strlen($email); $i++) {
        $obf .= '&#' . ord($email[$i]) . ';';
    }
    return $obf;
}

echo '<a href="mailto:' . obfuscate_email('info@company.com') . '">' . obfuscate_email('info@company.com') . '</a>';

HTML source code:

<a href="mailto:&#105;&#110;&#102;&#111;&#64;&#99;&#111;&#109;&#112;&#97;&#110;&#121;&#46;&#99;&#111;&#109;">&#105;&#110;&#102;&#111;&#64;&#99;&#111;&#109;&#112;&#97;&#110;&#121;&#46;&#99;&#111;&#109;</a>

What user sees:

info@company.com

You can use free external services like aemail.com :

@email is a free e-mail hiding service that hides emails using short URLs redirecting senders to the mailto-url after clicking the link.

After entering an email at aemail.com, you will get a short URL, which can be used to replace your 'mailto' link. Once link is clicked, your user will be redirected to the 'mailto' URL without any notice of the aemail.com. API can be used to hide emails/get URLs dynamically.

Example:

<a href="mailto:info@itee.com">Contact</a>

Replaced with

<a href="https://aemail.com/q2">Contact</a>

Will keep email link working.

The simplest solution is to create an image for your company email address :)

Or

You can use this online tool:

<script type="text/javascript">
  var part1 = "me";
  var part2 = "mydomain.com";
  var part3 = "Click Here to Send";
  document.write('<a href="mai' + 'lto:' + part1 + '@' + part2 + '">');
  document.write(part3 + '</a>');
</script>

Or

Check out for more methods:

您可以动态生成JavaScript中的mailto链接,如下所示: http//www.webmarksonline.com/content/dynamicemaillink.htm

I recommend recaptca . It makes uses type the words in two images before revealing your email. It's completely secure and it also helps to digitize books. The website provides a great API (copy-paste code) for implementing it on your site

Update - heres a direct link to mailhide

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM