the only other thing I can think of is explode the groups into the email array before you run the email script.
it might also be useful to explicitly set a return value for whether the email was able to send or not
Code:
$n_email = array();
foreach($email_ar as $email)
{
if(!stristr($email, "@") && !stristr($email, "."))
{
$res = mysql_query("SELECT * FROM `newsalert` WHERE `group`='$email'");
while($row = mysql_fetch_array($res))
{
$n_email[] = $result;
}
else
{
$n_email[] = $email;
}
}
if(!is_array($n_email))
$n_email[] = array($n_email);
foreach($n_email as $send)
{
if(sendMail($send))
{
$sent[] = $send;
}
else
{
$not[] = $send;
}
}
// track emails that were not sent;
print_r($not);
// track success emails sent;
print_r($sent);
Code:
function sendMail($email)
{
// gets rid of any leading/trailing whitespace in the email address
$to = trim($email);
$subject = "subject";
$from = "From: Name <email@domain.ext>";
$body = "Message Content";
if(mail($to,$subject,$body,$from))
{
return true;
}
else
{
return false;
}
}
Bookmarks