...

View Full Version : problem in mail() with \r\n



Mido™
10-26-2009, 12:48 AM
I have a mail() function and I make it to allow users to send messages to each others,so the user is who write the content of the message.
the problem in the \r \n characters,when the user write in a new line or take a space those characters show in his sent message to the other user with the other word.
hope and one have a solution.

Lamped
10-26-2009, 01:34 AM
You shouldn't use \r\n in the message content (only the headers, if you're specifying some manually). You can fix this by wrapping your content with str_replace("\r\n", "\n", content)

oesxyl
10-26-2009, 02:32 AM
I have a mail() function and I make it to allow users to send messages to each others,so the user is who write the content of the message.
the problem in the \r \n characters,when the user write in a new line or take a space those characters show in his sent message to the other user with the other word.
hope and one have a solution.
I don't understand what you mean. Can you give a example?

best regards

Mido™
10-26-2009, 01:41 PM
You shouldn't use \r\n in the message content (only the headers, if you're specifying some manually). You can fix this by wrapping your content with str_replace("\r\n", "\n", content)

I think you may misunderstood me,I didn't use this \r\n or write them or the user who write the message write them, but when the user who write the message take a break and start writing in a new line the character "\n" appear in the sent message to who read it.

Mido™
10-26-2009, 01:57 PM
I don't understand what you mean. Can you give a example?

best regards

ok,as I said the user is who write the content of the message and then it sent to the other user that he want to his email,so no one write this characters " \r \n " in the message but it appear in the sent message to who read it if who wrote it take a break and wrote in a new line.
I want a solution to avoid this character and in the same time make who wrote in a new line appear in a new line after sending the message.

Lamped
10-26-2009, 04:20 PM
Oh, you don't mean your recipient is literally getting "\n" in their email, not a new line but like:

Line 1\nLine2\nLine3

When it should be
Line 1
Line 2
Line 3

If that's the case, you want stripslashes or stripcslashes:

http://www.php.net/manual/en/function.stripslashes.php
http://www.php.net/manual/en/function.stripcslashes.php

oesxyl
10-26-2009, 04:46 PM
ok,as I said the user is who write the content of the message and then it sent to the other user that he want to his email,so no one write this characters " \r \n " in the message but it appear in the sent message to who read it if who wrote it take a break and wrote in a new line.
I want a solution to avoid this character and in the same time make who wrote in a new line appear in a new line after sending the message.
sorry, I still don't understand.
Anyway you can replace any \r, \n with a space before the user recive the message using this:


$newmessage = preg_replace("/[\r\n]/", " ",$oldmessage);

this will join the lines into a single one like this:


my message
is on few
lines

become:


my message is on few lines

.
I didn't test it, so let's me know if work and if is what you need.

best regards

Mido™
10-26-2009, 06:18 PM
Oh, you don't mean your recipient is literally getting "\n" in their email, not a new line but like:

Line 1\nLine2\nLine3

When it should be
Line 1
Line 2
Line 3

If that's the case, you want stripslashes or stripcslashes:

http://www.php.net/manual/en/function.stripslashes.php
http://www.php.net/manual/en/function.stripcslashes.php

exactly this is what I was meaning, but I used stripslashes and it didn't fix it.
also I notice that this probelm happen when I use mysql_real_escape_string() function, but I need to use it.

Lamped
10-26-2009, 06:24 PM
We could use a little more information then. Maybe some code?

abduraooft
10-26-2009, 06:24 PM
exactly this is what I was meaning, but I used stripslashes and it didn't fix it.
also I notice that this probelm happen when I use mysql_real_escape_string() function, but I need to use it.
You should use that function only when you use the data from any external variable(GPC) in your mysql queries. The data being passed to the mail() function shouldn't be passed to that function before.

oesxyl
10-26-2009, 06:56 PM
exactly this is what I was meaning, but I used stripslashes and it didn't fix it.
also I notice that this probelm happen when I use mysql_real_escape_string() function, but I need to use it.
mysql_real_escape_string take as argument the string so in the place you are using you can that variable for mail and the result of the function to insert in your data base. This way you don't need to remove \r,\n from the message.

best regards

Mido™
10-26-2009, 07:10 PM
You should use that function only when you use the data from any external variable(GPC) in your mysql queries. The data being passed to the mail() function shouldn't be passed to that function before.

I used it cause I thought it would give me more security,but you are right I don't need it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum