homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Java Email Body Spacing
Wondering how to include returns in the body of an email

 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



 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.

 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?


 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.


 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.


 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

 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 &amp?


 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?


 11:09 pm on Feb 7, 2012 (gmt 0)

<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();
<div style="border:2px solid black;padding:10px;">
Please <a href="#" onclick="emailForm();">Submit Complaint</a>

The "valid_email" is the first part of my email address so I changed that.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved