jamiller
03-14-2008, 05:58 PM
I'm creating an email script and am sending an 'email' variable to the send.php script. Because the email var isn't an array I make it one first:
$emails = $_POST['emails'];
$email_ar = split('[;,]', $emails);
I now need to send each individual email to the mailing function sendMail with the email address as a param. But in that email var above I have a bunch of groups that contain many emails. So first I need to select the group from my database and then all emails under that group. So that email var could look like: $emails = "group1; group2; test@testing.com"
I create foreach loop and an if else statement to decifer between "group" emailing lists and single email addresses as so:
foreach($email_ar as $email) {
// IF EMAIL IS A GROUP EMAIL
if(!stristr($email, "@") && !stristr($email, ".")) {
$result = mysql_query("SELECT * FROM `newsalert` WHERE `group`='$email'");
while($row = mysql_fetch_array($result)) {
sendMail($row['email']);
}
// ELSE IT'S A SINGLE ADDRESS
} else {
sendMail($email);
}
}
Wierd thing is that the if else statement within the foreach loop seems to just quit after the first element is processed. I'm thinking it could be a return false/true thing but don't really know where to put it...
$emails = $_POST['emails'];
$email_ar = split('[;,]', $emails);
I now need to send each individual email to the mailing function sendMail with the email address as a param. But in that email var above I have a bunch of groups that contain many emails. So first I need to select the group from my database and then all emails under that group. So that email var could look like: $emails = "group1; group2; test@testing.com"
I create foreach loop and an if else statement to decifer between "group" emailing lists and single email addresses as so:
foreach($email_ar as $email) {
// IF EMAIL IS A GROUP EMAIL
if(!stristr($email, "@") && !stristr($email, ".")) {
$result = mysql_query("SELECT * FROM `newsalert` WHERE `group`='$email'");
while($row = mysql_fetch_array($result)) {
sendMail($row['email']);
}
// ELSE IT'S A SINGLE ADDRESS
} else {
sendMail($email);
}
}
Wierd thing is that the if else statement within the foreach loop seems to just quit after the first element is processed. I'm thinking it could be a return false/true thing but don't really know where to put it...