0

请原谅这个诙谐的标题,但我在过去的一个小时里一直在努力让我的联系表格正常工作。它可以很好地发送电子邮件,但它会遗漏所有相关数据(姓名、电子邮件等)

我修改了一个 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";
}
?>
4

3 回答 3

2

你不需要引号。

$customer_name = "$name";
$customer_name = $name;

你真的应该使用 post 来获取数据。

$customer_name = $_POST['name'];
于 2011-09-13T02:46:28.600 回答
1

您需要在超级全局 $_POST 中查找变量。例如

$customer_name = $_POST['name'];
于 2011-09-13T02:47:24.903 回答
1

如果您发布需要从帖子中获取的数据:我也会修剪它

$customer_name = trim( $_POST['name'] );
于 2011-09-13T02:48:20.557 回答