在PHP中发送联系人表单数据

在PHP中发送联系人表单数据,php,Php,我已经开通了我的网站。我试图用PHP发送两个表单的数据。它工作正常,但问题是我在一行中接收所有数据。我试图实现的是让电子邮件中的所有数据都在换行符中。下面我将提到这两种形式的PHP代码。请指导我哪里做错了。提前谢谢 表格1: <? php ($_POST["email"]<>'') { $ToEmail = 'info@ad4u.pk'; $EmailSubject = 'Website Contact form'; $mailheader = "From: ".$_PO

我已经开通了我的网站。我试图用PHP发送两个表单的数据。它工作正常,但问题是我在一行中接收所有数据。我试图实现的是让电子邮件中的所有数据都在换行符中。下面我将提到这两种形式的PHP代码。请指导我哪里做错了。提前谢谢

表格1:

<? php
($_POST["email"]<>'') { 
$ToEmail = 'info@ad4u.pk'; 
$EmailSubject = 'Website 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 .= "phone: ".nl2br($_POST["phone"])."\r\n"; 
$MESSAGE_BODY .= "message: ".nl2br($_POST["message"]);
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
echo "<script> alert('Messgae successfully sent!');
window.location='index.html'</script>";
   exit;  
?>

  • “\r\n”
    替换为

  • 邮件前使用()
    哇-没有过滤提交的数据!如果你不清理帖子数据,你会让自己面临各种各样的不愉快!我还看到了一些其他的小问题:1)我认为没有理由使用
    text/html
    作为内容类型,您实际上没有将html放入文档中。2) 如果您使用Postfix作为邮件服务器,那么实际上预期MIME行终止符是底层操作系统的本地终止符,因此您应该使用
    PHP\u EOL
    而不是
    \r\n
    在每个
    $mailheader
    项的末尾。3) 不要使用JavaScript创建弹出窗口和重定向,只要使用PHP
    header()
    调用(HTTP 302)切换到消息传递脚本,如果您输出
    到浏览器,它将被缓存并可以重新加载。“请为我编辑代码”-我们通常不会在这里这样做。读者通常愿意提供帮助,但不愿意免费工作。。。。或者只需将
    内容类型设置为text/plain即可。
    
    <?php
    ($_POST["email"]<>'') { 
    $ToEmail = 'info@ad4u.pk'; 
    $EmailSubject = 'Website Price Inquiry 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 .= "Adress: ".nl2br($_POST["address"])."\r\n"; 
    $MESSAGE_BODY .= "phone: ".nl2br($_POST["phone"])."\r\n";
    $MESSAGE_BODY .= "product: ".nl2br($_POST["product"])."\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;  
    ?>