Mailto body text does not fill in IE
Asked Answered
P

3

7

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
Peasecod answered 21/6, 2011 at 12:45 Comment(3)
Is the link produced correctly?Streetwalker
shouldn't that be href="mailto:..." rather than href="email:.."Backfield
correct--I accidentally deleted that to keep the actual email address private. it is fixed now.Peasecod
L
13

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>
Lemmie answered 21/6, 2011 at 13:31 Comment(3)
For replacing # sign %23 worked for me. encodeURI() function did not.Trinitrotoluene
@ClearCloud8 Woops, didn't notice that the OPs code already had encoded line breaks, so encodeURI would have just re-encoded them. I put in a runnable version that set the mailto link instead of just putting it in a variable like the old example did. I also changed it to encode all three fields, instead of just the body (which is where the OPs problem was). What exactly didn't work for you?Lemmie
Once I replaced encodeURI by the encodeURIComponent it worked for me in IE11.Liegeman
S
2

Somewhere along these lines, you are drawing a false conclusion. Start by eliminating the dynamic link generation, and test using a static piece of HTML. If that doesn't work either, post the exact link that doesn't work. Perhaps you have invalid characters in your quote that you are not aware of. Does it perhaps start with an apostrophe?

From your code above, the link would look something like this:

<html>
  <body>

    <a href="mailto:[email protected]?subject=subject&body=Please enter your contact information and message here: %0A%0A%0AQuote:%0ARaaaawr">email</a>

  </body>
</html>

This works perfectly fine (tested IE9, Outlook2007).

Solberg answered 21/6, 2011 at 12:54 Comment(1)
Tried eliminating the dynamic link, but this didn't work. I have changed the example to reflect the specifics of my generated links. As you can see, the only special characters being used are pound signs for product numbers and dollar signs for prices.Peasecod
M
0

In addition to URL encoding the hash (#) as Fantabulum mentions, I would check which client they are using. If it is Outlook (as inferred from your tag selection) they may want to run a "Detect and Repair" (usually found on the Help menu).

Running "Detect and Repair" has fixed a number of issues with similar links on our intranet. Usually the problem is the result of a corrupt file/setting, or some other program jacking with Outlook - e.g. a Windows update reverting a registry key that Outlook had changed.

Mousseline answered 21/6, 2011 at 13:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.