Forum Moderators: coopster

Message Too Old, No Replies

line breaks are breaking my form

help!

         

HelenDev

8:46 am on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a form where users enter their enquiry into a textarea which is then put into a database and an email is sent. However, if users put line breaks in their enquiry this is getting screwed up. So I put this code in...

$enquiry = str_replace("\n", " ", $enquiry);

Now the form works (the mail gets sent) but the email is cutting off any text after the first line (although the db is capturing it), and the mail subject has mysteriously disappeared. Does anyone have any idea why this might be happening?

H (stressed out!)

ukgimp

9:00 am on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try the

nl2br($var);

It might work for you

HelenDev

9:12 am on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks, ukgimp,

but unfortunately the same problems persist :(

H

I probably should also mention that the mail is plain text, not html.

HelenDev

9:19 am on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Solved!

I needed to put this as well as the \n one...


$enquiry = str_replace("\r", " ", $enquiry);

What is the actual difference between \r and \n?

Anyone know any good php mail tutorials, I think I could use one! :)

H (blood pressure decreasing now).

ukgimp

9:47 am on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



[htmlite.com...]

escape characters

Timotheos

3:46 pm on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Correct me if I'm wrong but my perception was that "\r\n" evolved from Windows and "\n" is a Unix convention. I typically just use "\r\n" as the lowest common denominator.

ergophobe

4:29 pm on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



\r - Mac
\n - *nix
\n\r - Windows

BTW, Windows is the one that makes "sense" from an old typewriter perspective - linefeed then carriage return.

Tom

Timotheos

4:44 pm on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok ergophobe you got me searchin' for the history of the carriage return and line feed. Here tis... [en.wikipedia.org...]

BTW, in Windows it's \r\n not \n\r. Carriage return is first then linefeed. The VB constant is vbCrLf. Sorry, just me being pedantic. I'll get back to ergo now ;-)

ergophobe

5:35 pm on May 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




just me being pedantic.

I love pedantic. I should have looked it up!