My code as below
$ID = mysqli_real_escape_string($cnx, trim($data->id));
$MSG = mysqli_real_escape_string($cnx, trim($data->message));
$query = "REPLACE INTO mytbl ".
"(id, msg, dateentry, status, rate) ".
"VALUES ('$ID', '$MSG', NOW(), 'ok', '$RATE')";
$result =mysqli_query($cnx, $query) or die ("Can't execute query!");
$to = 'my@gmail.com';
$subject = 'my report';
$message = 'Message From User on: '. $MSG . "\r\n";
$headers = 'From: anonymous@mymail.com' . "\r\n" .
'Reply-To: anonymous@mymail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
In my message ($MSG), it contains new line, which is represented by \n. So when the email is sent, the \n persist, instead of the making a new line, it stays as \n. I would like it to be a new line instead of \n displaying on the email.
I have read about How to replace \r & \n with <br/>?, and think perhaps I could use double-quote instead of single, and work with nl2br, but of no success. Perhaps my value comes from somewhere else (i.e. $data->message), so I don't know how to make it a single quote or double quote string. Any light to shed?
Thanks!
(Note the $MSG is both used for DB insertion and Emailing)