Forum Moderators: open

Message Too Old, No Replies

line break in form textarea (plain text)

         

helenp

9:39 pm on Jun 17, 2008 (gmt 0)

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



Hi,
I already posted this in the php forum, but donīt seem to be a way of doing this, maybe there is a way of doing it in Javascript.
I use phpmailer and I manage to configure it to receive the emails as plain text instead of html.
Now the problem is that people do line breaks when writing their comments in the field textarea in the form. And I receive the email like this:
testing \r\nthis is a new line

I have managed to eliminte those ugly \r\n in the text but not to do a line break as intented the user.
If I do this:
$comments = str_replace("\\r\\n", " ", $comments);
I receive it like this:
testing this is a new line

That is a lot better, but do not have line break.

If I do this:
$comments = str_replace("\\r\\n", "\\n", $comments);
it write the \n and I get this result:
testing \nthis is a new line

Is there some way to do line break in plain text in Javascript and receive the email as line break?

httpwebwitch

2:22 am on Jun 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you are probably receiving mail in HTML format.

do this instead

$comments = str_replace("\\r\\n", "<br/>", $comments);

helenp

8:37 am on Jun 18, 2008 (gmt 0)

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



Thanks httpwebwitch.
No I receive the email as plain text (though that is what I want and the program is configured as plain text)
Any way, I tried it and I receive it like this doing it with <br/>
testing<br/>this is a new line

helenp

9:04 am on Jun 18, 2008 (gmt 0)

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



As per this thread:
[webdeveloper.com...]
it is a bug in outlook, therefore I receive the emails without the line break, and the solution is doing this:
$comments = str_replace("\\r\\n", "\n\n", $comments);
That works, but gives me 2 linebreaks

Br3nn4n

9:23 am on Jun 18, 2008 (gmt 0)

10+ Year Member



Just wondering, can you try this and see if it works?

$comments = str_replace ( chr(10), " ", $comments );

helenp

9:34 am on Jun 18, 2008 (gmt 0)

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



Thanks Br3nn4n,
just tried but give this:
testing\r\nthis is a new line