doulan3966 2013-08-31 15:08
浏览 10
已采纳

用HTML和PHP制作表格,但无法弄清楚出了什么问题

I made a form to email the data to an email ID. But upon filling up the form and submitting, the browser is saying:

Server error. The website encountered an error while retrieving http://localhost/process.php.

Here is the code:

form1.html

<html>
<head>
<title>Form</title>
</head>
<body>

<form method = "post" action = "process.php">
Enter your name <input type = "text" name = "namee" id = "namee" value = "enter your name" />
Enter your phone number <input type = "text" name = "phone" id = "phone" />
<br>
<input type  = "submit" value = "post it!" />
</form>


</body>
</html>

process.php

<?php

$person_name = $_POST["namee"];
$person_number = $_POST["phone"];

$to = "example234671_1@gmail.com";
$subject = "form filled up";
$body = $person_name. "<br>" $person_number . "<br>" . $person_name ;


mail($to, $subject, $body);

echo "Thank you!" ;
?>

What is the error??

  • 写回答

4条回答 默认 最新

  • douguazhi5966 2013-08-31 15:28
    关注

    In order to format email properly, headers using text/html must be used for <br> as line breaks.

    Otherwise, your email body will appear as John Doe<br>213-555-0123<br>etc.

    Plus, as the others have already stated, a missing concatenate in:

    $body = $person_name. "<br>" $person_number . "<br>" . $person_name ;
    

    which should read as:

    $body = $person_name. "<br>" . $person_number . "<br>" . $person_name;
    

    Rewrite with added headers:

    <?php
    
    $person_name = $_POST["namee"];
    $person_number = $_POST["phone"];
    $to = "example@gmail.com";
    $subject = "form filled up";
    $from="email@example.com";
    $body = $person_name. "<br>" . $person_number . "<br>" . $person_name;
    
    $header = 'MIME-Version: 1.0' . "
    ";
    $header .= 'Content-type: text/html; charset=iso-8859-1' . "
    ";
    $header .= "From: ". $from . " $from " . "
    ";
    
    mail($to, $subject, $body, $header);
    echo "Thank you!";
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿
  • ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址