mardi 24 février 2015

Submit form content to department based on drop down selection

I am 100% unskilled when it comes to PHP. In fact, I pretty much took this code from another site which shares stuff with the world. I'm creating a simple website for my neighborhood pool and we have to addresses, one for membership questions and one for general questions.


What I would like is for the form to be sent to one of these emails based on the type selected in the drop down field.


My contact form HTML is below:



<form action="contact.php" method="post">
Question Type:<br>
<select name="cf_dept">
<option>General</option>
<option>Membership</option>
</select><br>
Your name<br>
<input type="text" name="cf_name"><br>
Your e-mail<br>
<input type="text" name="cf_email"><br>
Message<br>
<textarea name="cf_message"></textarea><br>
<input type="submit" value="Send">
<input type="reset" value="Clear">
</form>


My php is:



<?php
$field_name = $_POST['cf_name'];
$field_email = $_POST['cf_email'];
$field_message = $_POST['cf_message'];

$mail_to = 'email address';
$subject = 'Message from website '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = 'http://website.com';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to email@provider.com');
window.location = 'http://website.com/';
</script>
<?php
}
?>


I have read through a number of websites including here but the language was really beyond my capability to comprehend so I apologize if this is an easy fix. If someone could post the revised code or let me know what I need to do using the simplest terminology possible I would greatly appreciate it.


Thanks.


Aucun commentaire:

Enregistrer un commentaire