I've created a HTML contact form which connects to a MySQL database to populate some options into a multiselect field.
I now need to send an email to a specific people depending on what values are selected in the MultiSelect field. But I can't figure out how to define the email addresses based on the selection.
This is the code I've used to populate the multiselect field.
$sql="SELECT addr1, city, status FROM listings WHERE status<>'Hidden' ";
$result=mysql_query($sql) or die(mysql_error());
$options="";
while ($row=mysql_fetch_array($result)) {
$addr1=$row["addr1"];
$city=$row["city"];
$status=$row["status"];
$options.="<OPTION VALUE=\"$addr1\">".$addr1 . ', ' . $city . ' - ' . $status;
}
<select multiple name="unit" id="unit" size="10" validate="required:true, rangelength:[1,5]">
<?=$options ?>
</select>
My Database structure looks like this
addr1 city status manager
address somecity available John Citizen
addresstwo city2 not available Jack Citizen
addressthree city3 available Jill Citizen
So when someone selects John Citizen and Jill Citizen, the email should be sent to those two people. I will also need to declare the email addresses for these two people via PHP variables. The Form will then be sent with this Code. (This code is in a different PHP file that the Form Action calls)
mail($emailaddresses,$subject,$html,"From: info@#####\r\nContent-type: text/html\r\n");
}
Is anyone able to give me some pointers? I have tried many things but can't get the selection working properly.