联系表单中的单选按钮不会发送信息

时间:2016-01-02 15:48:27

标签: php contact

我的联系表格中有两个单选按钮,如下所示:

<div class="field form-inline radio">
  <input class="radio" type="radio" name="response" value="ATTENDING" /><span>Blalala 1</span>
</div>
<div class="field form-inline radio">
  <input class="radio" type="radio" name="response" value="NOT ATTENDING" /><span>Blablabla 2</span>
</div>

/* ... */

<div class="form-group col-xs-12 floating-label-form-group controls">
  <label>Name</label>
  <input type="text" class="form-control"   placeholder="Name" id="name" required data-validation-required-message="Write your name">
  <p class="help-block text-danger"></p>
  </div>

然后来自互联网的一些通用contact_me.php:

<?php
// Check for empty fields
if(empty($_POST['name'])    ||
empty($_POST['email'])  ||
empty($_POST['phone'])  ||
empty($_POST['message'])    ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
 echo "No arguments Provided!";
 return false;
}

$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
$response = $_POST['response'];

/* ... */
$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\nPhone: $phone\n\nResponse: $response\n\nMessage:\n$message";
/* ... */

但是响应字段总是留在我收到的电子邮件中,无论尝试什么。我谷歌很多,没有任何帮助。我希望你能!

代码的其余部分来自模板,它可以工作,我添加了两个单选按钮,无法开始工作。

1 个答案:

答案 0 :(得分:0)

我希望您正在寻找:

您的HTML表单:

<form method='post' action=''>
<input type="text" name="name" value="">
<input type="text" name="email" value="">
<input type="text" name="phone" value="">
<input type="text" name="message" value="">
<input type="radio" name="response" value="Attend">Attend
<input type="radio" name="response" value="Not Attend">Not Attend

<input type="submit" name="submit" value="Submit"></form>

和PHP代码:

<?php
// Check for empty fields
if(empty($_POST['name'])    ||
empty($_POST['email'])  ||
empty($_POST['phone'])  ||
empty($_POST['message'])    ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
 echo "No arguments Provided!";
 return false;
}
else {

$name = $_POST['name'];
$email_address = $_POST['email'];
$message = $_POST['message'];
$phone = $_POST['phone'];
$response = $_POST['response'];

/* email body */
$email_body = "You have received a new message from your website contact form. \n\n
Here are the details: \n\n
Name: $name \n\n
Email: $email_address \n\n
Phone:  $phone \n\n
Response: $response \n\n
Message: \n $message";


$header = "From: noreply@example.com\r\n"; 
$header.= "MIME-Version: 1.0\r\n"; 
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n"; 
$header.= "X-Priority: 1\r\n";

mail(to, subject, $email_body, $header);
}

?>

我改变了什么:

  • 为所有字段添加适当的输入名称。
  • 在其他情况下移动成功阻止
  • 添加电子邮件标题