Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with mailto link in email address containing ampersand?

Tags:

html

mailto

I have a mailto link like that <a href="mailto:a&[email protected]" > it displays correctly on html but when we click on the link the outlook just shows a in the to address. Has anyone faced the same problem please suggest.

like image 947
sushil bharwani Avatar asked Feb 29 '12 11:02

sushil bharwani


People also ask

Can an email address have an ampersand?

Some email addresses that contain certain characters, such as the ampersand, may return as invalid recipients although the address is valid.

Why are mailto links not working?

If mailto links don't open for you the way they should, a quick look at the system or browser settings should do the job. In Windows, head to Settings -> Apps -> Default apps. Scroll down and pick “Choose default apps by protocol” from the menu. For 'Mailto', choose the client of your choice.

How do you mailto with subject and body?

subject=<subject> to the mailto tag. For example, the complete tag would look similar to the example below. You can also add body text by adding &body=body to the end of the tag, as shown in the example below. You can also include &cc= or &bcc= to fill out the CC and BCC fields.

Can links go to email addresses using mailto?

A mailto link is clickable text that automatically opens a new email in the reader's default email client, such as Outlook or Gmail, and pre-fills the "To" email address. Mailto links are great when you want emails on certain topics to go to a designated email account or employee.


1 Answers

Percent encoding the string is required for IE and I assume will work across browsers. From this MSDN document:

Windows Internet Explorer 7 and later. You must percent-encode all URL-reserved characters within a mailto: address. For example, the number sign (#) is used as a fragment identifier in URLs. When processing an address such as some#[email protected], Internet Explorer copies only the portion up to the number sign into the mail client; the fragment portion including the number sign is ignored. This behavior is by design.

So you need

 <a href="mailto:a%26b_admin%40xyz.com">

As said, I expect a percent encoded address will work in all browsers, but I don't know for sure. I can confirm it works with Chrome and Thunderbird.

like image 67
Pekka Avatar answered Nov 15 '22 22:11

Pekka