karimali831 Posted February 3, 2013 Share Posted February 3, 2013 (edited) Hi all, I am trying to send mail to multiple recipients using array, I am using two while loops to store values in $to array variable. $to[]=$to_email1['email']; $to[]=$to_email2['email']; there is two values stored in $to[]=$to_email1['email']; and one value stored in $to[]=$to_email2['email']; the below code only sends 2 emails when it is suppose to send 3? it does not send to the next value of $to[]=$to_email1['email']; so I assume it will only send to first every time? I have noticed when I start n=1; it gets only the email it does not send to when n=0; So I need the for loop to get all possible values. any help please I'd be thankful. sorry if unclear! <?php $query = safe_query("SELECT * FROM ".PREFIX."cup_clan_members WHERE clanID='$challenger_ma'"); while($to_ds3 = mysql_fetch_array($query)) { $to_email1=mysql_fetch_array(safe_query("SELECT * FROM ".PREFIX."user WHERE userID='".$to_ds3['userID']."'")); if(isleader($to_ds3['userID'],$challenger_ma)) { echo $to_email1['email'].'<br>'; $to[]=$to_email1['email']; $ni[]=$to_email1['nickname']; } } $query = safe_query("SELECT * FROM ".PREFIX."cup_clan_members WHERE clanID='$challenged_ma'"); while($to_ds4 = mysql_fetch_array($query)) { $to_email2=mysql_fetch_array(safe_query("SELECT * FROM ".PREFIX."user WHERE userID='".$to_ds4['userID']."'")); if(isleader($to_ds4['userID'],$challenged_ma)) { $to[]=$to_email2['email']; $ni[]=$to_email2['nickname']; } } $n=0; for ($n=0; isset($to[$n]) && isset($ni[$n]); $n++) { echo $to[$n].'<br>'; // subject $subject = 'Ladder Challenge Notification'; // message $message = ' <html> <head> <title>Ladder Challenge Notification</title> </head> <body> Hello '.$ni[$n].' </body> </html> '; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Additional headers $headers .= 'To: '.$ni[$n].' <'.$to[$n].'>' . "\r\n"; $headers .= 'From: '.$dt['title'].' <'.$sender_from.'>' . "\r\n"; $headers .= 'Cc: '.$sender_from . "\r\n"; // Mail it mail($to[$n], $subject, $message, $headers); $n++; } ?> Edited February 3, 2013 by karimali831 Quote Link to comment https://forums.phpfreaks.com/topic/273968-php-mail-array/ Share on other sites More sharing options...
Christian F. Posted February 4, 2013 Share Posted February 4, 2013 use var_dump () to see the contents of the $to and $ni arrays, before you loop through them. What the problem is should come to light then, if I'm not mistaken. Quote Link to comment https://forums.phpfreaks.com/topic/273968-php-mail-array/#findComment-1410046 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.