用PHP发送联系表单

时间:2015-02-14 15:59:06

标签: php html

我正在尝试通过电子邮件发送我网站的订单。它工作正常,但问题是我只用一行就能收到全部信息。我希望在每个领域之后都有一个换行符。我的代码是:

<?php
($_POST["email"]<>'') { 
$ToEmail = 'info@mysite.com'; 
$EmailSubject = 'Website order form'; 
$mailheader = "From: ".$_POST["email"]."\r\n"; 
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n"; 
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "Email: ".$_POST["email"].""; 
$MESSAGE_BODY .= "Adress: ".nl2br($_POST["address"]).""; 
$MESSAGE_BODY .= "product: ".nl2br($_POST["product"])."";
$MESSAGE_BODY .= "phone: ".nl2br($_POST["phone"])."";
$MESSAGE_BODY .= "quantity: ".nl2br($_POST["quantity"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
echo "<script> alert('Messgae successfully sent!');
window.location='index.html'</script>";
   exit;  

?>

请指导我错在哪里。提前致谢

1 个答案:

答案 0 :(得分:1)

如果您使用内容类型,则需要使用\r\n text / plain 如果您使用 Html

,请<br/>
<?php
($_POST["email"]<>'') { 
$ToEmail = 'info@mysite.com'; 
$EmailSubject = 'Website order form'; 
$mailheader = "From: ".$_POST["email"]."\r\n"; 
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n"; 
$mailheader .= "Content-type: text/plain; charset=iso-8859-1\r\n"; 
$MESSAGE_BODY = "Name: ".$_POST["name"]."\r\n";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."\r\n"; 
$MESSAGE_BODY .= "Adress: ".nl2br($_POST["address"])."\r\n"; 
$MESSAGE_BODY .= "product: ".nl2br($_POST["product"])."\r\n";
$MESSAGE_BODY .= "phone: ".nl2br($_POST["phone"])."\r\n";
$MESSAGE_BODY .= "quantity: ".nl2br($_POST["quantity"])."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
echo "<script> alert('Messgae successfully sent!');
window.location='index.html'</script>";
   exit;  

?>