请原谅这个诙谐的标题,但我一直在努力让最后一小时让我的联系表格正常工作。它发送电子邮件很好,但它遗漏了所有相关数据(姓名,电子邮件等)
我修改了PHP联系表单教程,但我不知道我哪里出错了。
HTML:
<form name="form1" method="post" action="send_contact.php">
<fieldset>
<h3>Name</h3>
<input name="name" type="text" id="name">
<h3>Email (required)</h3>
<input name="email" type="text" id="email">
<h3>Phone (required)</h3>
<input name="telephone" type="text" id="telephone">
<h3>Desired appointment time/date</h3>
<input name="time" type="text" id="time">
<input type="submit" name="Submit" value="Submit">
</fieldset>
</form>
PHP:
<?php
// customer name
$customer_name = "$name";
// customer email
$mail_from = "$email";
// customer telephone
$customer_telephone = "$telephone";
// desired appointment time
$appointment_time = "$time";
// subject
$subject = "Appointment for $customer_name";
// message
$message = "$customer_name would like to book an appointment for $appointment_time";
// header
$header = "from: $customer_name <$mail_from>";
// recipient
$to = 'my@emailaddress.com';
$send_contact = mail($to,$subject,$message,$header);
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>
答案 0 :(得分:2)
您不需要引号。
$customer_name = "$name";
$customer_name = $name;
你应该使用post来获取数据。
$customer_name = $_POST['name'];
答案 1 :(得分:1)
你需要在超级全局$ _POST中查找变量。例如
$customer_name = $_POST['name'];
答案 2 :(得分:1)
如果您发布了从帖子中获取数据所需的数据:我也会修剪它
$customer_name = trim( $_POST['name'] );