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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...