adding linebreak in mailto body

N

nAmYzArC

Hi everyone,

I'm setting the body of an email using values from a form

firstname = bob
lastname = dole

ebody = 'First Name: ' + firstname + '\r\n' + 'Last Name: ' + lastname

window.location.href = 'mailto:[email protected]?subject=test
email&body=' + ebody;

If I do an "alert(ebody);" I get the linebreak between firstname &
lastname, however when it opens up outlook, the entire ebody string
appears without a linebreak in the email body.

I've tried just \n also. is there something that can give be a line
break?
 
N

nAmYzArC

If you want to reliably send email, send it from the server.

This is not a requirement stated in my original question. I am well
aware of the advantages of sending email server-side. But thanks for
the input anyway.
 
M

Mr. Clean

This is not a requirement stated in my original question. I am well
aware of the advantages of sending email server-side. But thanks for
the input anyway.
Well using mailto to GENERATE a message is bogus to say the least and only
amateurs do it.

My suggestion would be to either...

1. Let the user CREATE the body and don't worry about adding any CR/LF
2. Use an some server component such as ASPMail to do it for you.
 
M

Mr. Clean

Hi everyone,

I'm setting the body of an email using values from a form

firstname = bob
lastname = dole

ebody = 'First Name: ' + firstname + '\r\n' + 'Last Name: ' + lastname

window.location.href = 'mailto:[email protected]?subject=test
email&body=' + ebody;

If I do an "alert(ebody);" I get the linebreak between firstname &
lastname, however when it opens up outlook, the entire ebody string
appears without a linebreak in the email body.

I've tried just \n also. is there something that can give be a line
break?
On another note...

Outlook doesn't understand \r\n means CR/LF...

Try using:

ebody = 'First Name: ' + fromCharCode(10) + fromCharCode(13) +
'Last Name: ' + lastname;
instead.
 
R

rh

Vjekoslav Begovic said:
It's an HTML issue. Put: ebody = 'First Name: ' + firstname + '%0D' + 'Last
Name: ' + lastname
You may also want to check this article:
http://www.itworld.com/nl/html_tutor/03122002/

That article appears to have dropped a character in describing the
escape sequence for \r\n -- it has "%0D%0" where "%0D%0A" was
apparently intended.

Since Javascript provides an "escape" function, would it not be
preferable to simply escape the text, and avoid the special code
arcana?

../rh
 
L

Laurent Bugnion, GalaSoft

Hi,

Vjekoslav said:
It's an HTML issue. Put: ebody = 'First Name: ' + firstname + '%0D' + 'Last
Name: ' + lastname
You may also want to check this article:
http://www.itworld.com/nl/html_tutor/03122002/

I can not believe that you, in a technical newsgroup, post a link to an
article praising a technique so deeply flawed that using it is like
throwing a stone in a well and hoping to receive an answer by email.

If the well is inhabited by a dwarf who happens to have an internet
connection, and that by chance your email address is written on the
stone, you might actually receive an email back. Using mailto: as
described in this "article" has approximately the same amount of chances
to work like you expect it.

It cannot be stressed enough: Using mailto with anything else than an
email address doesn't work reliably enough that it's worth even
mentioning it. Just forget it, it doesn't work. What's worse is: When it
doesn't work, you cannot have any feedback from your users, since they
cannot send you any email.

If you don't have any access to CGI (like the excellent, and free,
formmail for example), then use a free service provider, for example
Bravenet.

Laurent
 
V

Vjekoslav Begovic

I can not believe that you, in a technical newsgroup, post a link to an
article praising a technique so deeply flawed that using it is like
throwing a stone in a well and hoping to receive an answer by email.

That article describes the use of mailto link, and OP wants to use mailto
link. Why he wants to do that, that's not my problem.
If the well is inhabited by a dwarf who happens to have an internet
connection, and that by chance your email address is written on the
stone, you might actually receive an email back. Using mailto: as
described in this "article" has approximately the same amount of chances
to work like you expect it.

It cannot be stressed enough: Using mailto with anything else than an
email address doesn't work reliably enough that it's worth even
mentioning it. Just forget it, it doesn't work. What's worse is: When it
doesn't work, you cannot have any feedback from your users, since they
cannot send you any email.

If you don't have any access to CGI (like the excellent, and free,
formmail for example), then use a free service provider, for example
Bravenet.

OK, but OP asked <cite>is there something that can give be a line
break?</cite>.
 
N

nAmYzArC

Whoa people -
There seems to be alot of un-needed debate here.
Let me try to simplify things:

1) I AGREEE that using server site mailing is the way to go.

2) I have a REQUREMENT to use only .htm pages. (NO server-side
programming is allowed. A mailto link seemed to be the only logical
route given the requirements.)

3) My question was NOT "Server-side vs Client-side mail. pros/cons?".
It was:
"How do i add a LINEBREAK in a mailto body"

Honestly, I like seeng some healthy debate on subjects, but in this
case, when I came back to the thread the conversation amused me and
seemed somewhat like the following:

Me: "I need bananas. Where can I find a place near me that sells
bananas?"

Vjekoslav: "Down the street, to your right." - original question
ANSWERED!!!!

Everyone else: "Why not have an Apple instead? They have more vitamins
and less calories. Apples are the way to go. Also, fruit is not the
way to go. Veggies instead have no seeds yada yada.." - original
question remains unanswered, AND topic changes!!!

P.S. I am not a fruit/vegetable expert. I do not take any
responsibility for any adverse effects on anyone's health based on my
fruit & vegetable commentary. :)
 
N

nAmYzArC

actually a plain old '%0D' works great as a linebreak in outlook. That's all I need.
 
L

Laurent Bugnion, GalaSoft

Hi.
Whoa people -
There seems to be alot of un-needed debate here.

<snip>

Sorry, but I disagree. You asked a question and you got an answer.
Having noticed that, I consider it my duty to give you some insights
about the bad solution that you choose to apply. Nothing in your first
post lets us know that you're not a total newbie, and god knows that we
see a lot of them around here. I consider that they deserve to get a
little knowledge.

A good way to avoid this kind of debate would have been to start your
post with "I am aware that mailto should never be used like I intend to
do, and yet I need to do it anyway".

We have only as much information as you give us. Don't complain when you
receive good quality answers adapted to the quantity of information you
gave.

I strongly believe that people who answer posts in a technical
newsgroups have a certain duty towards the people they answer to.
Pointing your misuse of mailto certainly is part of that.

Friendly,

Laurent
 
N

nAmYzArC

Mr. Clean said:
On another note...

Outlook doesn't understand \r\n means CR/LF...

Try using:

ebody = 'First Name: ' + fromCharCode(10) + fromCharCode(13) +
'Last Name: ' + lastname;
instead.

Actually using this gave me an 'object expected' error.
 
M

Mr. Clean

Actually using this gave me an 'object expected' error.


Without seeing your complete code, I can't tell what would be causing that
because fromCharCode(10) should work just fine.
 
L

Lasse Reichstein Nielsen

Mr. Clean said:
Without seeing your complete code, I can't tell what would be causing that
because fromCharCode(10) should work just fine.

Shouldn't that be "String.fromCharCode(10)"?
/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top