Search code examples
phpgoogle-chromemailto

Using Chrome's "Copy email address" on mailto link returns encoded useless text instead of a correct email address


We have a website with restricted access (only for exclusive members) coded in PHP.

On the Contact page we have a bunch of mailto links, for example:

<a href="mailto:Name SURNAME <[email protected]>">[email protected]</a>

If a visitor clicks on one of the links, it does the usual stuff (opens a new email in Thunderbird with the To: field correctly filled in).

The problem is when a visitor right-clicks on one of the links, selects "Copy email address" and then pastes it in the To: field or wherever (even in a document), in which case the result would be:

Name%20SURNAME%20%[email protected]%3E

instead of

Name SURNAME <[email protected]>

I've been searching for a solution for hours and already tried rawurlencode(), urlencode() and other possible tricks, with absolutely no effect.

Can some of you please help me?

Here is the PHP code that generates the link:

<?php  echo '<a href="mailto:'.$name.' <'.$email.'>'.'">'.$email.'</a>'; ?>
//where $email is a valid email address
//and $name is plain text (usually two words with a space character between)

Solution

  • I believe you're trying to do something that simply cannot be done. I understand the idea but... it's not a thing.

    I found no docs saying that you can put a name and enclose the email address in <>.

    1. https://developer.mozilla.org/.../a#Creating_an_email_link
    2. https://developer.mozilla.org/.../Creating_hyperlinks#E-mail_links
    3. IETF RFC6068

    You can of course do:

    <a href="mailto:[email protected]">[email protected]</a>