Saturday, 31 August 2013

Using Drop Down Selects With My PHP Code To Send To My E-mail

Using Drop Down Selects With My PHP Code To Send To My E-mail

I am trying to go off the PHP code I had for my contact page (with no drop
down selects, all text fields) which worked perfect. But when I try to
make it work with Drop Down Selects, it doesn't work, it just keeps giving
me errors.
Here is my HTML for one drop down select: (i tried both, with and without
the [] after the name)
<select data-placeholder="Select a category" name="category[]" id="selK6U"
style="display: none;" class="chzn-done">
<option></option><option value="Snack &amp; Quick Meals"
data-connection="snackSelect">Snack &amp; Quick Meals</option><option
value="Wraps" data-connection="wrapSelect">Wraps</option><option
value="Breads" data-connection="breadSelect">Breads</option><option
value="Chicken Entrees" data-connection="chickenSelect">Chicken
Entrees</option><option value="Lahawajawaab Mutton"
data-connection="laSelect">Lahawajawaab Mutton</option><option value="Rice
Dishes" data-connection="riceSelect">Rice Dishes</option><option
value="Vegetarian" data-connection="vegSelect">Vegetarian</option>
</select>
and here is my PHP code:
<?php
if(isset($_POST['email'])) {
$email_to = "email@myemail.com";
$email_subject = "subject";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form
you submitted: <br />";
echo $error."<br />";
echo "Please fix these errors.<br />";
die();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['phone']) ||
!isset($_POST['address']) ||
!isset($_POST['city']) ||
!isset($_POST['zip']) ||
!isset($_POST['category']) ||
!isset($_POST['meal']) ||
!isset($_POST['spicy']) ||
!isset($_POST['delivery']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form
you submitted.');
}
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$phone = $_POST['phone']; // not required
$phone = $_POST['address']; // not required
$phone = $_POST['city']; // not required
$phone = $_POST['zip']; // not required
$category = $_POST['category']; // not required
$meal = $_POST['meal']; // not required
$spicy = $_POST['spicy']; // not required
$delivery = $_POST['delivery']; // not required
$message = $_POST['message']; // not required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be
valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The First Name you entered does not appear to be
valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Name: ".clean_string($name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Phone: ".clean_string($phone)."\n";
$email_message .= "Address: ".clean_string($address)."\n";
$email_message .= "City: ".clean_string($city)."\n";
$email_message .= "Zip: ".clean_string($zip)."\n";
$email_message .= "Meal Category: ".clean_string($category)."\n";
$email_message .= "Meal: ".clean_string($meal)."\n";
$email_message .= "How Spicy: ".clean_string($spicy)."\n";
$email_message .= "Delivery: ".clean_string($delivery)."\n";
$email_message .= "Other Details: ".clean_string($message)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
echo 'Thank you, your message has been sent! <br /> We will review
your submission and contact you as soon as possible.';
}
?>
Any help would be GREATLY appreciated. Thank You!

No comments:

Post a Comment