Hi guys,
I hope you can help me please. I am experiencing a weird problem, which wasn't happening before I moved my server over to a new host on a dedicated server.
The problem is basically, when we take $_POST data from a textarea, a new line in there seems to get duplicated. So let's say the user presses their enter key twice to start a whole new line, on the mail() it ends up as 4.
Weirdly though, as you will see by the below code, we also insert the reply into a reply database. In there, it's absolutely fine. I have maunally checked my MySQL Database, and can confirm it looks perfect
I have the following function in my functions.php, but I don't think it's to do with it (but it's the only thing that touches $_POST). We had it before the server mode, and magic_quotes is off so I don't even think it's being used:
if (get_magic_quotes_gpc()) {
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}
Code:
$write=1;
$msg = "";
if (empty($_POST['reply'])) {
$write=0;
$msg .= "<li><span>Please fill in the Reply field</span></li>\n";
}
if (!empty($msg)) {
echo "<p>Please correct the following:</p>\n<ul>\n$msg\n</ul>\n\n";
exit();
}
if ($write==1)
{
$dateadded=date("Y-m-d H:i:s");
$sql="Insert into replydb (id_ticket,name,dateadded,reply,user) values (".mysql_real_escape_string(htmlentities($ticket['id_ticket'])).",'".mysql_real_escape_string($_SESSION['account'])."','".mysql_real_escape_string($dateadded)."','Some of our standard text followed by the reply via:\n\n".mysql_real_escape_string(htmlentities($_POST['reply']))."\n\n*** End ***',1)";
$writesql=mysql_query($sql);
$subject = "Re: Ticket [ID:".htmlentities($ticket['id_ticket'])."]";
$headers = "From: Web <noreply@us.net>\r\n";
$headers .= "X-Mailer: PHP ".phpversion()."\r\n";
$headers .= "Staff-ID: ".$_SESSION['account']."\r\n";
$headers .= "X-Originating-IP: ".$_SESSION['ip']."\r\n";
$msg="Some of our standard text followed by the reply via:\n\n".$_POST['reply']."\n\n*** End ***";
mail($ticket['email'], $subject, $msg, $headers);
echo " <ul>\n <li><span>Sent!</span></li>\n </ul>\n\n";
}
So, by the above code, it appears when it gets mail()'ed it goes crazy. Also, with GMail (only gmail I've seen) the "X-Originating-IP" header appears as the message text, which is weird too (it never used to do that)
Any help appreciated!