return true/false? if else in foreach
Posted: Wed Mar 19, 2008 2:48 pm
I'm in the middle of making an email program in php/mysql that sends a variable to my main emailsend.php script. This variable holds the recipients of the email. When the var is sent over it isn't an array so I make it one first:
I now need to send each individual email to the mailing function I've made, sendMail with the email address as a param, sendMail($emailaddy); But in that var above I have a bunch of groups that contain many email addresses. So I first need to select the group from my database and then all emails under that group. So if I echoed out the $emails var it could look like: group1; group2; test@testing.com.
I create a foreach loop and an if/else statement to decifer between "group" emailing lists and single addresses like so:
My sendMail function looks like so:
For testing purposes all sendMail does for now is echo out the param.
Wierd thing is that the foreach loop only processes the first array element. If it is a group it will correctly echo out all emails associated with the group and nothing more. Same if the first array element is a single address. It echoes only one address and then stops.
There is no other php code on the page other than a db connection script. The array split works fine. I've used print_r($email_ar) which prints: Array ( [0] => group1 [1] => group2 [2] => test@testing.com ).
So I'm thinking, and I could be very wrong here, that it's a return true/false thing (???). But after hours and days working on this script I'm about ready to throw my computer out the window!!
Please Help!! My computer is too young to go now, she still has a lot in her...
THANKS! -Jeff
Code: Select all
$emails = $_POST['emails'];
$email_ar = split('[;,]', $emails);
I create a foreach loop and an if/else statement to decifer between "group" emailing lists and single addresses like so:
Code: Select all
foreach($email_ar as $email) {
if(!stristr($email, "@")) { //GROUP MAILING LIST
$result = mysql_query("SELECT * FROM `newsalert` WHERE `group`='$email'");
while($row = mysql_fetch_array($result)) {
sendMail($row['email']);
}
} else { //SINGLE ADDRESS
sendMail($email);
}
}
Code: Select all
function sendMail($emailaddy) {
echo $emailaddy . "<br />";
}
Wierd thing is that the foreach loop only processes the first array element. If it is a group it will correctly echo out all emails associated with the group and nothing more. Same if the first array element is a single address. It echoes only one address and then stops.
There is no other php code on the page other than a db connection script. The array split works fine. I've used print_r($email_ar) which prints: Array ( [0] => group1 [1] => group2 [2] => test@testing.com ).
So I'm thinking, and I could be very wrong here, that it's a return true/false thing (???). But after hours and days working on this script I'm about ready to throw my computer out the window!!
Please Help!! My computer is too young to go now, she still has a lot in her...
THANKS! -Jeff