I am trying to adapt a SELECT option in a contact form.
Based on a selection, I trying to assign an email address of the email recipient based on the selection.
I tried it with if else if but it did not work. CASE appears not to work either.
Can anyone help?
[php]
<?php $errors = ''; $equipment = $_POST['equipment']; switch ($equipment) { case 'Vehicle': $myemail = '[email protected]'; echo "Mailto: ".$myemail.""; case 'Communication': $myemail = '[email protected]'; echo "Mailto: ".$myemail."
"; case 'Camera': $myemail = '[email protected]'; echo "Mailto: ".$myemail."
"; case 'Other': $myemail = '[email protected]'; echo "Mailto: ".$myemail."
"; } $name = $_POST['name']; $email_address = $_POST['email']; $phone = $_POST['phone']; $grade = $_POST['grade']; $message = $_POST['message']; if (!preg_match( "/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", $email_address)) { $errors .= "\n Error: Invalid email address"; } if( empty($errors)) { $to = $myemail; $email_subject = "Information request from: $name"; $email_body = "You have received a new message. ". " Here are the details:\n Name: $name \n $phone \n Email: $email_address \n Message \n $message"; $headers = "From: $myemail\n"; $headers .= "Reply-To: $email_address"; mail($to,$email_subject,$email_body,$headers); header('Location: contact-form-thank-you.html'); echo "Message deliverd"; } ?>
[/php]
[php]
Send to:
Vehicle
Communications
Camera
Other
Your Name:
Email:
Phone:
Message:
Your
Message…