email message in javascript

Posted on 2003-03-04
Medium Priority
Last Modified: 2011-09-20

I have a problem with a small piece of JavaScript that is meant to set up an email message from clicking a link.  My problem is that I can't seem to put blank lines in an email message.

In my HTML I have something like this:
  <a href="javascript:mailpage()">Click here to email</a>

In the mailpage function, I have something like this:

mailpage() {
  mail_str = "mailto:?subject= the email subject";
  mail_str += "&body=   Line 1.";
  mail_str += "Line 2.";
  location.href = mail_str;

My problem is that I can't seem to set up the email message so that there will be a blank line between Line 1 and Line 2 in the message body.  So the message body of the email should be like this:


I've tried "\n\r", and also "\012\015", which have no effect at all.  Can anybody help me with this?
Question by:djschick
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8064919
You can only do this one way. Take the contents of a textarea field and pass them as the body.

Read this article for more information:


In the end, it has nothing to do with what you are doing. E-mail programs will only accept a limited amount of data from the client browser. If you want to do this correctly, I would allow the user to send an e-mail via a form and use CGI to process it.

Expert Comment

ID: 8065049
The \f escape character for line feed will work.

mailpage() {
 mail_str = "mailto:?subject= the email subject";
 mail_str += "&body=   Line 1.";
 mail_str += "\fLine 2.";
 location.href = mail_str;

Good Luck!

LVL 19

Accepted Solution

webwoman earned 140 total points
ID: 8065115
Since nobody has mentioned it, I will.

Mailto is inherently FLAKEY. Whatever you do, it's possible that it may not work. Even if it's RIGHT, it might not work.

Mailto relies TOTALLY on the client. Have a web mail client? Won't work. Have a proprietary client? Won't work. Have an older browser? Won't work. Have security settings high? Won't work. User doesn't send the mail? Won't work.

You may get an attachment with the querystring, nothing, a decent email, a blank mail -- and you have NO control over it.

If you REALLY want this to work, use a server side script. Chances are your ISP/hosting company has a form handler you can use. Find out and use it.

Expert Comment

ID: 8065287
I agree with webwoman, and to clarify her point further, I use Outlook Express 6 and the \f escape does not work for me.

Author Comment

ID: 8065719
Thanks for the info everybody!  Unfortunately the suggestions that people here didn't work for me, so I had to choose the best explanation why.

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question