Jump to content

php mail array


karimali831

Recommended Posts

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++;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/273968-php-mail-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.