First you must change the name of your select box so that the selected items will end up in an array.
<select name="to[]" size="10" multiple>
Now there are two ways of doing this. You can either use a loop and call mail() one time for every chosen email or you can use the BCC or CC header.
Here is the version with the loop:
<?php
$recip = $_POST['to'];
foreach($recip as $email) {
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; ";
$headers.= "charset=iso-8859-1\r\n";
$headers.= "From: [email]me@myaddres.com[/email]";
$subject = "Some Subject";
$body = "Some Message";
$send_check=mail($email,$subject,$body,$headers);
if ($send_check!=true) {
die('An error occurred while sending mail.');
}
}
?>
This solution will work nicely as long as you're not sending emails to too many persons. If you're gonna send a lot of mails at a time then I recommend using the BCC header. This code will send an email to your email and a blind carbon copy to all the other specified emails.
<?php
$recip = $_POST['to'];
$to = "me@myaddres.com";
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; ";
$headers.= "charset=iso-8859-1\r\n";
$headers.= "From: [email]me@myaddres.com[/email]";
foreach($recip as $rec) {
$headers .= "Bcc: $rec\r\n";
}
$subject = "Some Subject";
$body = "Some Message";
$send_check=mail($to,$subject,$body,$headers);
if ($send_check!=true) {
die('An error occurred while sending mail.');
}
?>
I havent tested the codes above so let me know if it doesn't work.