Mail Form - sending data to different email addresses
Posted: Tue Dec 02, 2008 1:36 am
Hi there,
I am trying to make a php form for a website, and I need a little help. My form will have fields for name, email, address, phone, enquiry and State (that you live in) and maybe more.
Here is where I need the help :
The 'state' will be a drop down menu, and depending on what state is chosen, the forms data will be sent to a different email address. There will be 7 'states', so 7 possible email addresses.
Here is the code I have been working off of. I'm pretty new to this, so i would really appreciate it being spelt out for me.
Thanks for your time.
I am trying to make a php form for a website, and I need a little help. My form will have fields for name, email, address, phone, enquiry and State (that you live in) and maybe more.
Here is where I need the help :
The 'state' will be a drop down menu, and depending on what state is chosen, the forms data will be sent to a different email address. There will be 7 'states', so 7 possible email addresses.
Here is the code I have been working off of. I'm pretty new to this, so i would really appreciate it being spelt out for me.
Code: Select all
<?php
if(isset($_POST['submit'])) {
$to = "test@test.com";
$subject = "Enquiry";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$address_field = $_POST['address'];
$ph_field = $_POST['phone'];
$state_field = $_POST['state'];
$enquiry_field = $_POST['enquiry'];
foreach($_POST['check'] as $value) {
$check_msg .= "Checked: $value\n";
}
$body = "From: $name_field\n Address: $address_field\n Email: $email_field\n Contact Phone Number: $ph_field\n \n State: $state_field\n Enquiry: $enquiry_field \n";
echo "Thank you blah blah blah";
mail($to, $subject, $body);
} else {
echo "Sorry, an Error blah blah";
}
?>