I have some code which isnt working and im not sure why.
Basically i have a drop down menu in a form and depending on wich one you pick, sends the email to different people:
<?php
function SendMail( $email_to ) {
$personalinjuryEmailArray = array( "julian.yates1@gmail.com", "jools105@hotmail.com" );
$credithireEmailArray = array( "enquiry@julian-yates.co.uk" );
switch( $_POST['department'] ){
case "1":
foreach ( $personalinjuryEmailArray as $email_to ){
SendMail( $email_to );
}
break;
case "2":
foreach ( $credithireEmailArray as $email_to ){
SendMail( $email_to );
}
break;
}
$email = strip_tags($_POST['email']);
$message = "Title: " . strip_tags($_POST['title']) . "\r\n";
$message .= "Name: " . strip_tags($_POST['name']) . "\r\n";
$message .= "Email Address: " . strip_tags($_POST['email']) . "\r\n";
$message .= "Address: " . strip_tags($_POST['address']) . "\r\n";
$message .= "Telephone: " . strip_tags($_POST['telephone']) . "\r\n";
$message .= "Message: " . strip_tags($_POST['comment']) . "\r\n";
$headers = "From: $email\r\n";
$headers .= "Reply-To: $email\r\n";
$subject = "Website Contact Form Enquiry". $subject;
if(mail($email_to, $subject, $message, $headers)){
echo 'sent'; // we are sending this text to the ajax request telling it that the mail is sent..
}else{
echo 'failed';// ... or this one to tell it that it wasn't sent
}
}
?>
HTML code for drop down:
<div class="right"><select name="department" id="department">
<option value="" selected>Please select</option>
<option value="1">Personal Injury</option>
<option value="2">ULR & Credit Hire</option>
</select></div>
any help mich appreciated
thanks