Page 2 of 2

Posted: Sat Sep 10, 2005 8:11 am
by raghavan20
ok thanx but what would i use?
I couldn't get it too work...

It doesn't want to replace "\r\n" with "\n"... (i tried with) ereg_replace. Somehow it will always be shown wrong in the email.
try to use addslashes instead of mysql_real_string since it replaces every /n with /n/r and /n/r is interpreted properly as a break in my browser(try for compatibility on both IE and Mozilla).

If you still use mysql_real_string() to escape something,,,then you can even use str_replace to change /r/n to /n

Code: Select all

str_replace("/n/r", "/n", $your_message);
you actually shouldn't have to escape anything for the message component, you know..
Actually I have seen only two places where we have to escape a string
1. database insertion
2. url variables.

In other cases, I dont think ',",/ are going to give some problems as feyd said.

Posted: Sat Sep 10, 2005 8:12 am
by feyd
rag, my comment was specific to this context. Yes, escaping those are required for many other operations, but in this case, they shouldn't. If anything, you should make sure they are all \r\n characters...

Posted: Sat Sep 10, 2005 1:10 pm
by joachimseitz
input is always:
test
test

Code: Select all

<FORM method="post">
<textarea name="content"></textarea><INPUT type="submit" name="send">
</FORM>
<?
if ($_POST['content']){
//if I echo $content; here i get: "test\r\ntest"
$content=mysql_escape_string($_POST['content']);
//str_replace i do here!!
echo $content;
mail('j_sendler@arcor.de', 'Feedback', $content, "From: Admin <joachimseitz@hotmail.com>");
}
?>
ps. yours doesnt work but i know what u mean

for:

Code: Select all

$content=str_replace('\r\n', '\n', $content);
i get this in my email:
test\ntest
no new line just \n
:?:

Posted: Sat Sep 10, 2005 1:12 pm
by feyd
as I've said, you shouldn't have to do any of that for them in this particular case. Also, know that in single quotes, \r and \n or any of the other "special" metacharacters aren't parsed. You're literally adding '\' and 'n' not a carriage return. Use double quotes to have them parsed.

at most, you may need to use stripslashes() to fix magic_quotes