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

Edited by karimali831
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.