Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

email message in javascript

Posted on 2003-03-04
5
Medium Priority
?
205 Views
Last Modified: 2011-09-20
Hi,

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:
Line1.

Line2

I've tried "\n\r", and also "\012\015", which have no effect at all.  Can anybody help me with this?
0
Comment
Question by:djschick
5 Comments
 
LVL 3

Expert Comment

by:bjrcreations
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:

http://tech.irt.org/articles/js080/index.htm

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.
0
 
LVL 1

Expert Comment

by:mbochniak
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!

Mike
0
 
LVL 19

Accepted Solution

by:
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.
0
 
LVL 3

Expert Comment

by:bjrcreations
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.
0
 

Author Comment

by:djschick
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.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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

581 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