0

I am trying to use the mailto function using an HTML form to populate a new message with some predefined text from an ASP string variable. I am using the syntax

<form action="MAILTO:someone@example.com?subject=<%= eSubject%>&body=<%= eBody%>" method="POST" enctype="text/plain">

where eSubject and eBody are string variables that have been drawn from values read from a DB and edited so that they use %20 instead of spaces and %0D%0A to represent new lines. The form contains no inputs and uses JavaScript to simply submit it straight away.

I have researched possible problems with the length of the string I am trying to pass to the body text (e.g. Limit on mail body when posting a mailto: form), but I get the impression it is up to a browser and only becomes an issue at fairly high character counts (depending on my inputs this varies between ~380 and 400 for my eBody string but is never more than 400).

The thing that is most frustrating is that my subject string (one line) populates the subject line of the new email as required. Could it be something to do with attempting to use newlines within my string? An example of the subject line is:

Query%20-%20Birmingham%20-%2025/03/2015%20at%2013:30

to produce subject line

Query - Birmingham - 25/03/2015 at 13:30

I am well aware that the general response to questions about using mailto is "Why are you doing that?!", but for in this case it is appropriate as the idea is to create an email that will always contain eBody (some info that is sent to customer services to show exactly what was happening at the moment of sending the query) and a message from the person sending the email, which will be different every time.

Any constructive help would be hugely appreciated. Thanks

Community
  • 1
  • 1
BGESjack
  • 13
  • 3

2 Answers2

0

It seems like the maximum character count can vary from browser to browser and also email client to email client (Getting around mailto / href / url character limit).

The accepted answer on this question (Effective maximum mailto: body lengths) mentions that Outlook Express's limit is 456 characters (possibly for the mailto link as a whole). So depending on your browser and possibly client, you may run into a limit. The other answer on that question could allow you to run some tests as well.

Community
  • 1
  • 1
chrisg
  • 76
  • 5
0

The w3c standard for mailto:, states:

According to RFC 822, the characters "?", "&", and even "%" may occur in addr-specs. The fact that they are reserved characters in this URL scheme is not a problem: those characters may appear in mailto URLs, they just may not appear in unencoded form. The standard URL encoding mechanisms ("%" followed by a two-digit hex number) must be used in certain cases. ...

As described above, the "&" (ampersand) character is reserved in HTML and must be replacded with "&". Thus, a complex URL that has internal ampersands might look like:

Click <a href="mailto:?to=joe@xyz.com&amp;cc=bob@xyz.com&amp;body=hello"> mailto:?to=joe@xyz.com&amp;cc=bob@xyz.com&amp;body=hello</a> to send a greeting message to <i>Joe and Bob</i>.

Therefore your example;

<form action="MAILTO:someone@example.com?subject=<%= eSubject%>&body=<%= eBody%>" method="POST" enctype="text/plain">

Should probably have the &body encoded such that it becomes &amp;body

<form action="MAILTO:someone@example.com?subject=<%= eSubject%>&amp;body=<%= eBody%>" method="POST" enctype="text/plain">

Robadob
  • 5,319
  • 2
  • 23
  • 32