Stainystain Stainystain - 1 year ago 60
PHP Question

Select element not posting

I'm struggling a little - can anybody explain why the select element is not posting for me? The rest of the form fields are posted into the email just fine, it's just the select is blank.
Many thanks for any help!

<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>
<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">
<input type="text" class="form-inputs" name="postcode">
<input type="submit" class="send" value=" Contact Us ">

$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 = "";
$subject = "Email Subject";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");

{print "Thank you message"; }

Answer Source

In your $formcontent variable, you specify $type as the variable to print in the e-mail. However, you named that variable $accidenttype above. The variable $type is null, which is why you get an empty result.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download