Wondering how to include returns in the body of an email
rahmuss
9:47 pm on Feb 4, 2012 (gmt 0)
Just wondering if there is a way to include returns in the body of an email which is made up of primarily variables.
var email = "mine@yours.com"; var subject = "Subject Here"; var body1 = "Body 1 segment"; var body1 = "Body 2 segment"; var body1 = "Body 3 segment";
var mailto_link = 'mailto:'+email+'?subject='+subject+'&body=Line1: '+body1+' Line2: '+body2+' Line3: '+body3;
I want it to output like this:
Line1: Body 1 segment Line2: Body 2 segment Line3: Body 3 segment
penders
11:22 pm on Feb 4, 2012 (gmt 0)
You should probably be url encoding (percent triplet) the parameter values, in which case the newline would be %0A (ascii 10) and carriage return %0D (ascii 13). I guess this will be down to the email client whether it is handled as expected.
rahmuss
12:17 am on Feb 5, 2012 (gmt 0)
Like this?
var mailto_link = 'mailto:'+email+'?subject='+subject+'&body=%0ALine1: '+body1+' %0ALine2: '+body2+' %0ALine3: '+body3;
Or, instead of %0A I could use %0D instead?
penders
1:04 am on Feb 5, 2012 (gmt 0)
Yes. That works for me on Windows with Thunderbird. Just the newline (LineFeed / %0A) character should be sufficient I would have thought.
rahmuss
5:39 pm on Feb 6, 2012 (gmt 0)
Strange. I tried that; but now it doesn't even send an email. Although I think I have bigger problems because I need to be able to change the subject each time.
penders
6:21 pm on Feb 6, 2012 (gmt 0)
...it doesn't even send an email.
Doesn't send? Or doesn't open the email client?
...+subject+'&body=%0ALine1: '...
Just to add, if this is used in an HTML document then the ampersand should be entity encoded as &
rahmuss
12:29 am on Feb 7, 2012 (gmt 0)
It doesn't send the message (no message received) and it doesn't even open the email client to send the message. What about with a "?", do I need to make that different like the &?
penders
7:39 am on Feb 7, 2012 (gmt 0)
You don't need to encode the "?".
Can you post the exact code you are using?
rahmuss
11:09 pm on Feb 7, 2012 (gmt 0)
<html> <body> <script type="text/javascript"> function emailForm(){ var daReferrer = document.referrer; var email = "valid_email@gmail.com, valid_email@hotmail.com"; var errorMsg = "error message"; var subject = document.subject.value; var name = "John Doe"; var complaint = "The product was faulty"; var ttime = "12:00"; var tdate = "Jan 1, 2012"; var mailto_link = 'mailto:'+email+'?subject='+subject+ttime+tdate+'&body=Complaint: '+complaint; win = window.open(mailto_link,'emailWindow'); if (win && win.open &&!win.closed) win.close(); } </script> <div style="border:2px solid black;padding:10px;"> Please <a href="#" onclick="emailForm();">Submit Complaint</a> </div> </body> </html>
The "valid_email" is the first part of my email address so I changed that.