Hi.
I've made a suggestion for you. It works the way that the email adresses won't be displayed at all.
First it pulls the name and an id from the db to be displayed as checkboxes in the form. User selects whivh persons to send email to.
After form is submitted the script will query the database again (getting email adresses) based on the the checkboxes that the user ticked.
The script just send one email to all the adresses at one time.
PHP Code:
<?php
error_reporting(E_ALL);
if(count($_POST) > 0 && $_POST['submit'] == 'sendemail') {
$msg = isset($_POST['msg']) ? $_POST['msg'] : '';
$to = isset($_POST['to']) ? $_POST['to'] : '';
if(!empty($to) && is_array($to)) {
$in = '';
foreach($to as $id) {
$in .= ", $id";
}
$in = trim(substr($id, 1));
}
$sql = "SELECT name, email FROM TABLE WHERE id IN ($in)";
$result = mysql_query($sql) or die(mysql_error());
$to = '';
while($row = mysql_fetch_array($result)) {
$name = $row['name'];
$email = $row['email'];
$to .= ", $name <$email>";
}
$to = trim(substr($to, 1));
if(mail($to, 'Subject', $msg)) {
echo 'Mail has been successfully send.';
} else {
echo 'An error occured. The mail didn\'t get sent.';
}
} else {
$sql = "SELECT id, name FROM table";
$result = mysql_query($sql) or die(mysql_error());
$checkboxes = '';
while($row = mysql_fetch_array($result)) {
$id = $row['id'];
$name = $row['nane'];
$checkboxes .= "<input type=\"checkbox\" name=\"to[]\" id=\"to\" value=\"$id\" />$name";
}
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<label for="to">Sen email to:</label>
<?php echo $checkboxes; ?>
<label for="msg">Message:</label>
<textarea name="msg" id="msg"></textarea>
<button type="submit" name="submit" value="sendemail">Send email</button>
</form>
<?php
}
?>
The script can be shortened if you don't worry about the email adresses beeing displayed. Then you only need one database quesy aswell.
Remeber to customize the sql/queries. I've not tested the code, so there might be some bugs. 
-Helge
Bookmarks