我的 PHP 联系表单一片空白

发布于 2024-12-04 06:38:29 字数 1516 浏览 0 评论 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 = '[email protected]'; 

$send_contact = mail($to,$subject,$message,$header);

if($send_contact){
    echo "We've recived your contact information";
}
else {
    echo "ERROR";
}
?>

Please forgive the tongue-in-cheek title, but I've been trying for the last hour to get my contact form to work properly. It sends the email just fine but it leaves out all the relevant data (name, email, etc.)

I've modified a PHP contact form tutorial, but I don't know where I've gone wrong.

The 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>

The 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 = '[email protected]'; 

$send_contact = mail($to,$subject,$message,$header);

if($send_contact){
    echo "We've recived your contact information";
}
else {
    echo "ERROR";
}
?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光无声 2024-12-11 06:38:30

你不需要引号。

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

您确实应该使用 post 来获取数据。

$customer_name = $_POST['name'];

You don't need quotes.

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

You should really use post to grab the data.

$customer_name = $_POST['name'];
岁月打碎记忆 2024-12-11 06:38:30

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

$customer_name = $_POST['name'];

you need to be looking in the super global $_POST for your variables. for example

$customer_name = $_POST['name'];
寄离 2024-12-11 06:38:30

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

$customer_name = trim( $_POST['name'] );

if your posting the data you need to get it from the post: I would trim it also

$customer_name = trim( $_POST['name'] );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文