Forum Moderators: coopster

Message Too Old, No Replies

new line form text/plain

         

helenp

11:36 am on Jun 17, 2008 (gmt 0)

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



Hi, 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 php? if not maybe in Javascript?

cantona

3:10 pm on Jun 17, 2008 (gmt 0)

10+ Year Member



Hi

Are you running the message body through an escaping function?

And is the body text string in double or single quotes?

Would help if you pasted some code examples :)

helenp

3:28 pm on Jun 17, 2008 (gmt 0)

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



Dear Cantona,
Thanks,
this is the body message, the other I did not understand.
Anyway the program is phpmailer.

$mail->Body = "Name: $name \nTelephone: $tel \nCountry: $country \nEmail: $repeat_email \nProperty: $property \nArrival: $arrival \nDeparture: $departure \nAdults: $adults \nChildren: $children \nComments: $comments\n";

cantona

3:35 pm on Jun 17, 2008 (gmt 0)

10+ Year Member



What happens if you comment out the str_replace() you're doing and just do:

$mail->Body = "Name:\t\t$name\n\n Telephone:\t\t$tel\n\n Country:\t\t$country\n\n ...\n\n";

That should work. I'm using like this and get a new line:

$phpmailer->Body .= "Email:\t\t{$_POST['email']}\n";

helenp

4:09 pm on Jun 17, 2008 (gmt 0)

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



Dear Cantona,
Thanks but I think I have not explained myself correctly.
I do receive all the variables in the body correctly with the linebreak.
The problem is inside the textarea...where the user write their comments. Instead of just keep writing they do line breaks but and I do not get those line breaks.

henry0

6:28 pm on Jun 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try using in reading mode nl2br [php.net]

helenp

7:03 pm on Jun 17, 2008 (gmt 0)

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



Thanks henry0
I already looked at that, or I dont understand how to do it, or it only works to do <br> for html.
I want to do a \n for plain text.
Is it posible using that for \n?

helenp

9:03 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:31 am on Jun 18, 2008 (gmt 0)

10+ Year Member



Helen, I responded in your post in Javascript.
[webmasterworld.com...]

[edited by: coopster at 2:18 pm (utc) on June 20, 2008]
[edit reason] added link to message referred to in JavaScript Forum [/edit]