代码如下。我希望它将[From:xxxxxx]部分分开,以便身体/消息的其余部分显示在不同的行上。
<?php
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$recipient = "me@christianselig.com";
$subject = "Message From Website";
$body = "[From: " . $name . "]\n\n" . $message;
$headers = "From: " . $email . "\r\n";
$headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";
$success = mail($recipient, $subject, $body, $headers);
echo $success;
?>
答案 0 :(得分:2)
您应该使用HTML代码<br />
代替\n
像这样:
$body = "[From: " . $name . "]<br /><br />" . $message;
使用mail()
函数的建议:
if( mail($recipient, $subject, $body, $headers) )
echo 'Success';
else
echo 'Fail';
编辑1
当您尝试以纯文本形式发送时,应使用\r\n
,这是纯文本中新行的转义序列。例如:
$formcontent="[From: " . $name . "]\r\n\r\n" . $message;