user3150191
user3150191

Reputation: 415

Add a line break when emailing \r\n PHP mail()

$order="";
$order .= "<strong>Sent:</strong> ";
$order .= date("F j, Y, g:i a");
$order .= "\r\n";
$order .= "\r\n";
$order .= $message;

My code works, however, I'm trying to add a line break between the date function and the $message. I've tried it with just \n, but nothing seems to work. Is there a different way? I echo out $order and there are no line breaks between the date and $message.

I also tried

$order .= '<br />'; but that did not work either. Any help?

FULL CODE:

<?php
session_start();
if(isset($_POST['order'])){
$message = $_POST['order'];
}
$order="";
$order .= "<strong>Sent:</strong> ";
$order .= date("F j, Y, g:i a");
$order .= "\r\n";
$order .= "\r\n";
$order .= $message;

//print_r($_POST);
echo $order;
include "imagehover.php";

    $email_to = "[email protected]";
    $email_subject = "Subject Line";
    $email_from = "[email protected]";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <[email protected]>' . "\r\n";

'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($email_to, $email_subject, $order, $headers);  
session_destroy();
?>

Upvotes: 0

Views: 1411

Answers (1)

Funk Forty Niner
Funk Forty Niner

Reputation: 74217

This line is incomplete/broken:

'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();

Replace with this whole block:

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: <[email protected]>" . "\r\n" .
                "Reply-To: $email_from" . "\r\n" .
                'X-Mailer: PHP/' . phpversion();

And:

Change it to:

$order="";
$order .= "<strong>Sent:</strong> ";
$order .= date("F j, Y, g:i a");
$order .= "<br>";
$order .= "<br>";
$order .= $message;

Upvotes: 1

Related Questions