Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mailto body text does not fill in IE

I am using mailto to allow submission of product quote information by customers. I am attempting auto-populate the quote into the email body by constructing the mailto link as a string, and concatenating the quote information, per the following code:

var quoteinfo = 'quote information here';
var link = '<a href="mailto:email?subject=subject&body=Please enter your contact information 
and message here: %0A%0A%0AQuote:%0A' + quoteinfo + '">email</a>';

However, when using IE, when the link is clicked, the email is generated, but only the text that is explicitly added appears--nothing stored in the quoteinfo variable shows up. I have verified that the final link does contain all of the quote information--it just is not appearing in the email. Since the email does successfully generate with part of its text, I do not believe this is a character overflow problem (and in any case, this happens even with as few as 30 characters in the quoteinfo variable.

Perhaps this is a problem specific to the mail client?

A final note: I am well aware that there is a popular movement toward replacing mailto with forms--for other reasons, I cannot do that here, so please refrain from responding by advising a switch to a form.

A specific example of how my links would appear is as follows:

mailto:[email protected]?subject=Submission From Quote Creator &body=Please enter
your contact information and message here: %0A%0A%0AQuote:%0A#17350 - IFW 2-inch -
$829.00%0A
like image 755
CodeRedd Avatar asked Jun 21 '11 12:06

CodeRedd


People also ask

How do you add body text to mailto?

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.

How do I pass HTML formatted body in mailto?

It is not possible to pass the HTML in email body while using mailto link. It takes only string/text value. It says, for line breaks, instead of using <br /> use %0D%0A .

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.


1 Answers

The hash symbol (#) has special meaning in URLs (remember anchor names? e.g. http://example.com#TopOfPage). Replace it with%23.

See W3's URL Encoding Reference

Better yet, JavaScript can do it for you with the encodeURI() function.

window.onload = function() {
  var eTo = encodeURI("[email protected]");
  var eSubj = encodeURI("Submission From Quote Creator");
  var eBody = encodeURI("Please enter your contact information and message here: \n\n\nQuote:\n#17350  IFW 2-inch -$829.00\n");

  var email = "mailto:" + eTo + "?subject=" + eSubj + "&body=" + eBody;

  document.getElementById("sales").href = email;
}
<a href="" id="sales">email</a>
like image 65
Gary Avatar answered Oct 23 '22 01:10

Gary