Checkbox to select a group of users for $_POST mail

I’ve only recently begun working with databases, and my knowledge for processing forms is limited to this. So far, I’ve created a form that selects a group of recipients for a newsletter, and stores them in a $get variable according to the selection.

I’m hoping someone nice enough will help me figure out how to send individual emails to the selected recipients when the form is submitted.

First, here’s part of the form, for reference:

Mailing List

SEND TO:
checked = "checked" <?php } ?>/> Austin Area
checked = "checked" <?php } ?> /> DFW Area

Second, here’s WHAT PERTAINS to the script i need help with. If something unrelated is missing, don’t worry, I’ve tested the form, and it processes fine. Just need help with the indicated areas below. THANKS IN ADVANCE!:
[php]
if (array_key_exists(‘send’,$_POST)) {

//Setup database variables
if ($location ==“ATX”) {
$get = mysql_query(“SELECT * FROM E_list WHERE status = ‘activated’ AND location=‘ATX’”);
}
if ($location ==“DFW”) {
$get= mysql_query(“SELECT * FROM E_list WHERE status = ‘activated’ AND location=‘DFW’”);
}
if ($location ==“ATX,DFW”) {
$get = mysql_query(“SELECT * FROM E_list WHERE status = ‘activated’”);
}
$additionalHeaders = “From: veeps [email protected]\r\n”;
$subject = ‘Veeps News’;

if ($_POST && empty($missing)) {
//create email
$body = “ADD TEXT HERE, AND CONCATENATE MORE LATER”;
//loop through results
for ($x=0; $x<count($_POST); $x++) {
if( //criteria help needed here)
{
$to = //value per criteria above
}// end if
} //end for loop
$mailSent = mail($to, $subject, $body, $additionalHeaders);
}
}
?>
[/php]

I think I got it. Some amendments have been made, in order to fix the $location variable, as well as its resulting $get sql query. PLEASE let me know if there are problems with my code (mind you, I’ve left out much unrelated code for easy reading). But for example, I was pretty sure that I needed to set a counter, in order to tell the loop when to stop. So far, it seems to be working alright:

[php]if (array_key_exists(‘send’,$_POST)) {
$header = “this is a header”;
$subject = ‘NEWS’;

//if missing, add to $missing
$missing = array();

if(!isset($_POST[‘location’])) {
$_POST[‘location’] = array();
$location = null;
echo “

PLEASE SELECT A LOCATION

”;
}
else {
$location = implode(’,’,$_POST[‘location’]);
}
//setup database variables
if ($location ===“ATX”) {
$get = mysql_query(“SELECT * FROM E_list WHERE status = ‘activated’ AND location=‘ATX’ OR status=‘activated’ AND location=‘ATX,DFW’”);
}
elseif ($location ===“DFW”) {
$get= mysql_query(“SELECT * FROM E_list WHERE status = ‘activated’ AND location=‘DFW’ OR status=‘activated’ AND location=‘ATX,DFW’”);
}
elseif ($location ===“ATX,DFW”) {
$get = mysql_query(“SELECT * FROM E_list WHERE status = ‘activated’”);
}

$message = $_POST[‘message’];
if ($_POST && empty($_POST[‘message’])) {
$mailSent = false;
array_push($missing, $message);
echo “

THERE IS NO MESSAGE TO SEND.

”;
}

//send it
if($_POST && empty($missing)) {
while($getrow = mysql_fetch_assoc($get))
{
$to = $getrow[‘email’];
$e_name = $getrow[‘name’];
$body = “Dear $e_name\r\n”;
$body .= $message;
$mailSent = mail($to, $subject, $body, $header);
}
}
} //end if($_POST
?>[/php]

<!DOCTYPE ...
Sponsor our Newsletter | Privacy Policy | Terms of Service