Hi Everyone,
I am trying to post a form using php mail() function to the person selected in a from a option drop down box.
My drop down box shows
<label for="contact">Job Contact:*</label>
<select id='contact' name='contact'>
<option value='' selected='selected'>Please select</option>
<option value='name1'>Name2</option>
<option value='name2'>Name1</option>
</select>
Which I get the value.
$contact = $_POST['contact'];
Compare with users
switch ($contact) {
case "name1":
$to = "name1@example.co.uk";
break;
case "name2":
$to = "name2@example.co.uk";
break;
}
mail($to, …, …, …);
I can not see why switch does not work?
if i use $to on its own the form sends.
Any ideas would be a great help.
There are several points of failure here;
You could try expanding your switch (for debugging purposes only) to do something like this:
This will force your switch to handle the contents of
$contactif it desn’t match any of the switches.Secondly, try to make sure that
$toactually contains a value.Do this by adding ‘var_dump($to); right before the
mail()function.This is basic debugging – and I suspect that one of those will tell you where the error is.