在以下代码中,$message 在 html 中显示时有新行(包装在 pre 标记中),但未在电子邮件中显示(我将其发送到我的 gmail):
error_reporting(E_ALL);
ini_set('display_errors', 'on');
include "../code/dbstuff.php";
$to = "me@mail.com";
$from = "";
function processMessage($arr) {
global $from;
$message = "Hello from me\n\n\n";
foreach ($arr as $key => $val) {
if (isset($_POST[$key])) {
$message.=$val . ": " . $_POST[$key] . "\n\n";
} else {
$message.=$val . ": empty" . "\n\n";
}
}
$message.= "Date: " . date('l F d, Y');
from = $_POST['contact_email'];
return $message;
}
$message = processMessage(array(
"firstname" => "First Name",
'lastname' => 'Last Name'
));
//save in db
$conn=new db();
$conn->insertMessage($from,$message);
mail( $to,$message,"From: $from" );
header( "Location: thankyou.php" );