【发布时间】:2019-07-08 23:54:58
【问题描述】:
我收到了一份表格,希望将填写好的表格发送到我的电子邮件地址。 我的代码不能正常工作(我对 PHP 没有太多经验)。 所以 - 我收到一封电子邮件,但没有输入表单的文本。 我的代码中有什么遗漏或错误?
<!--Contact-->
<section id="contact" class="get-in-touch">
<h1 class="title">Contact <span>us!</span></h1>
<p class="contact-p text-center">Lorem Ipsum.</p>
<form class="contact-form row" method="GET" action="contact_me.php">
<div class="form-field col x-50">
<input id="name" class="input-text js-input" type="text" required>
<label class="label" for="name">Name</label>
</div>
<div class="form-field col x-50">
<input id="email" class="input-text js-input" type="email" required>
<label class="label" for="email">E-Mail</label>
</div>
<div class="form-field col x-100">
<input id="message" class="input-text js-input" type="text" required>
<label class="label" for="message">Message</label>
</div>
<div class="form-field col x-100 align-center">
<input class="submit-btn" type="submit" value="Send">
</div>
</form>
</section>
<?php
$name = $_GET['name'];
$email_address = $GET['email'];
$message = $GET['message'];
// Create the email and send the message
$to = 'user@gmail.com'; //This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nMessage:\n$message";
$headers = "From: noreply@yourdomain.com\n"; // This is the email address the generated message will be from.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
?>
所以我希望收到输入姓名、电子邮件和消息的电子邮件,但我只收到了 $email_body 的文本,没有输入用户的文本。它只是空白。
输出如下所示: Output
您已收到来自您的网站联系表单的新消息。
以下是详细信息:
姓名:
电子邮件:
消息:
【问题讨论】: