Jump to content
Larry Ullman's Book Forums

Outputting data from function escape_data without '\r\n'


Recommended Posts

I am sure this is a stupid question but I'm tearing my hair out.

I am trying to email data that I have cleaned (from a multi-line text box) with escape_data.

The problem is the data is sent with \r\n instead of actual line breaks. Eg: message in email will read "Hello\r\nThis is the 1st parapgraph\r\n\r\nThis is another"

I have tried to remedy this below but it does not work:

    if ($_POST['Information'] != '') {
        $Information = escape_data($_POST['Information'], $dbc);
        $Informationformatted = str_replace(array("\r\n", "\r", "\n"), "<br />", $Information); 
    } else {
        $contact_errors['Information'] = 'Please enter your message';
    }

//message in email
$body = $Informationformatted;

$headers = 'MIME-Version: 1.0'. "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= 'From:'.$Email;
 mail ('email@email.com', 'Message', $body, $headers); 

I am still getting the same output: "Hello\r\nThis is the 1st parapgraph\r\n\r\nThis is another"

I have also tried $Informationformatted = nl2br($Information);

This did not work either.

(Or would be something to do with the headers?)

Link to comment
Share on other sites

You're running the values through escape_data(), which probably means that the incoming \n (for example) gets turned into \\n which is why nothing else works from there on. And I would just use nl2br() instead of str_replace().

Link to comment
Share on other sites

 Share

×
×
  • Create New...