Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Banned
    Join Date
    Mar 2007
    Posts
    1,523
    Thanks
    116
    Thanked 0 Times in 0 Posts

    Question PHP email converts new line to \r\n?!

    Please help,

    When I sent an email like this:

    test body
    next line
    www.google.co.uk

    it came to my email like this:

    test body\r\nnext line\r\nwww.google.co.uk

    here is my code:
    PHP Code:
    <?php
    mysql_connect
    ("xxx""xxx""xxx");
    mysql_select_db("xxx");
    $EmailTitle mysql_real_escape_string($_POST['EmailTitle']);
    $EmailBody mysql_real_escape_string($_POST['EmailBody']);
    $id mysql_real_escape_string($_POST['id']);

    $query5 mysql_query("SELECT * FROM aarbookts_booking_bookings WHERE id = '$id'");
    $row5 mysql_fetch_array($query5);
        
    $customer_name $row5['customer_name'];

    $to $row5['customer_email'];
    $subject $EmailTitle;
    echo 
    $to;

    $message = <<<EOF
    <html>
      <body>
        <p>$EmailBody</p>
      </body>
    </html>
    EOF;
       
    //end of message
        
    $headers  "From: me@myemail.com\r\n";
        
    $headers .= "Content-type: text/html\r\n";

        
    //options to send to cc+bcc
        //$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
        //$headers .= "Bcc: [email]email@maaking.cXom[/email]";
        
        // now lets send the email.
        
    mail($to$EmailTitle$message$headers);
       
    $msg "Mass email sent"
    header("Location: send-mass-email.php?msg=$msg"); 
      
    ?>

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I assume that is provided by the $_POST['EmailBody']? These should NOT be run through a mysql_real_escape_string. They should instead be run through a str_replace and presumably followed by an nl2br:
    PHP Code:
    $EmailBody nl2br(str_replace("\r\n""\n"$_POST['EmailBody'])); 
    Mysql_real_escape_string is used ONLY for data being placed into a SQL query.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •