联系表格php显示电子邮件格式查询

时间:2017-08-30 09:19:20

标签: php html forms contact

这是PHP代码。 当电子邮件显示在email-id上时,内容应该在下一行。

$ToEmail = 'abc@gmail.com'; 
$EmailSubject = 'Exza Contact 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"]."\n"; 
$MESSAGE_BODY .= "Email :".$_POST["email"]."\n"; 
$MESSAGE_BODY .= "Subject : ".$_POST["subject"]."\n"; 
$MESSAGE_BODY .= "Message : ".nl2br($_POST["message"])."\n"; 
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");

示例:

  

姓名:Abc
  电子邮件:abcd@gmail.com
  主题:任何
  消息:所有工作

1 个答案:

答案 0 :(得分:0)

只需使用\r\n代替\n

$ToEmail = 'abc@gmail.com'; 
$EmailSubject = 'Exza Contact 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"]."\r\n"; 
$MESSAGE_BODY .= "Email :".$_POST["email"]."\r\n"; 
$MESSAGE_BODY .= "Subject : ".$_POST["subject"]."\r\n"; 
$MESSAGE_BODY .= "Message : ".nl2br($_POST["message"])."\r\n"; 
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");