I have an HTML form that I have a "select" drop-down menu that is selecting the name of the person you should send to. The names are being pulled from the Database, and here is what that code for the drop-down in the form looks like:
<?php
echo '<select name= "First_Name" , "Last_Name">';
while( $array = mysql_fetch_assoc($result) ) {
$text_for_select = $array["First_Name"] . " " . $array["Last_Name"]. " " . $array["District"];
$value_for_select = $array["First_Name"] . " " . $array["Last_Name"] . "_" . $array["id"];
echo "<option></option>\n";
echo "<option value=\"$value_for_select\">$text_for_select</option>\n";
}
echo '</select>';?>
This works perfectly. However, what I want it to do is send the form to the email address of the person that is selected in the drop-down. The email address' are already entered in each record of the database in a field called "Email". I am using the $value_for_select variable to pull the id of the record, but I am unsure how to then tell the form to send to the email address of that record? Anybody know a way that this can be done?
<?php
if($_POST){
$to = $email;
$subject = "WHAT SHOULD THIS BE";
$message = "Date: $date\n\r".
"Dear $First_Name, $Last_Name,\n\r".
"Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah.Blah Blah BLah..\n\r".
"Sincerely,\n".
"$name \n".
"$street \n".
"$city, $zip \n".
"$email \\n".
$headers = "From: $email";
mail($to, $subject, $message, $headers);
// SUCCESS!
echo '<p class="notice">'.
'Thank you for your submission. '.
'</p>';
// clear out the variables for good-housekeeping
unset($date,$legislator,$bill,$name,$street,$city,$zip,$email);
$_POST = array();
}
?>
Please let me know how this can be achieved.
Thanks in advance!