选择元素而非发布

时间:2016-11-06 14:58:53

标签: php forms select option

我有点挣扎 - 任何人都可以解释为什么选择元素不适合我?其余的表单字段很好地发布到电子邮件中,它只是选择是空白的。 非常感谢您的帮助!

<form action="/mail.php" method="POST">
<div id=”mainselection”>
<select name="type">
<option value="one">One</option>
<option value="two">Two</option>
<option value="three">Three</option>
<option value="four">Four</option>
<option value="five">Five</option>
<option value="six">Six</option>
<option value="seven">Seven</option>
</select>
</div>
<p>Full Name</p>
<input type="text" class="form-inputs" name="name">
<p>Email Address</p> 
<input type="text" class="form-inputs" name="email">
<p>Mobile Number</p> 
<input type="text" class="form-inputs" name="phone">
<p>Postcode</p>
<input type="text" class="form-inputs" name="postcode">
<input type="submit" class="send" value=" Contact Us ">
</form>

<?php 
$accidenttype = $_POST['type'];
$name = $_POST['name'];
$email = $_POST['email'];
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
{
    die("E-mail address not valid<br><br>

You are now being redirected back");
}
$phone = $_POST['phone'];
$postcode = $_POST['postcode'];
$formcontent="Type: $type \n From: $name \n Email: $email \n Phone: $phone \n postcode: $postcode";
$recipient = "email@address.com";
$subject = "Email Subject";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

{print "Thank you message"; }
?>

1 个答案:

答案 0 :(得分:1)

$formcontent变量中,指定$type作为要在电子邮件中打印的变量。但是,您将上面的变量命名为$accidenttype。变量$type为null,这就是为什么你得到一个空结果。