RE: [PHP-DB] Phpmailer sending duplicate messages...

2007-11-01 Thread Instruct ICC

   while($row = mysqli_fetch_assoc($result))
   {
  extract($row); 
 
 $mail-IsSMTP();
 $mail-Host = host.com; 
 $mail-From = [EMAIL PROTECTED];
 
 $mail-From = [EMAIL PROTECTED];
 $mail-FromName = Company;
 $mail-AddAddress($email, $Contact);
 
 $mail-IsHTML(True);  
 $mail-Subject = $Subject;
 $mail-Body = $PR;
 $mail-WordWrap = 50;
 
 
 
 if(!$mail-Send())
 {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail-ErrorInfo;
 }
 else
 {
echo 'Message has been sent.';
 }
 
 }

I bet your while loop over the extract is causing you to have:
user1
user1, user2
user1, user2, user3,...

Instead of polluting your symbol table, can't you just use the email field?
$email = $row['theEmailField'];

I've used code like this back in the day (Notice how the array $arr was unset):
$recipients = [EMAIL PROTECTED][EMAIL PROTECTED][EMAIL PROTECTED];
parse_str($recipients);
for($i=0; $icount($arr); $i++){
mail($arr[$i], $subject, $message, From: $sender\n. Reply-To: 
$sender\n);
}
unset($arr);


_
Boo! Scare away worms, viruses and so much more! Try Windows Live OneCare!
http://onecare.live.com/standard/en-us/purchase/trial.aspx?s_cid=wl_hotmailnews

Re: [PHP-DB] Phpmailer sending duplicate messages...

2007-11-01 Thread Stut

Stephen Sunderlin wrote:

It seems to be ccing each email to everyone and I'd like it to only include
one email address with each email.  I've tested in on three of my personal
emails and I see to get six messages in my inbox.

I'm also sending about 4000 emails and would like some pointers to avoid
time out errors.

Finally for the life of me can't figure out how to execute an insert
statement to record a history of each email sent.  When I include the insert
statement, no emails are send.

Following is the code.

Any help or direction would be greatly appreciated.

Thanks.

**


?php

require(class.phpmailer.php);
$mail = new PHPMailer();

include (cxnfile);  
	$cxn = mysqli_connect($host,$user,$password,$database)

 or die (Couldn't connect to server);

$query =  select *
From db
where groupid = groupid;

$result = mysqli_query($cxn,$query)
or die(Couldn't execute select query.);

while($row = mysqli_fetch_assoc($result))
{
 extract($row); 


$mail-IsSMTP();
$mail-Host = host.com; 
$mail-From = [EMAIL PROTECTED];


$mail-From = [EMAIL PROTECTED];
$mail-FromName = Company;
$mail-AddAddress($email, $Contact);

$mail-IsHTML(True);  
$mail-Subject = $Subject;

$mail-Body = $PR;
$mail-WordWrap = 50;



if(!$mail-Send())
{
   echo 'Message was not sent.';
   echo 'Mailer error: ' . $mail-ErrorInfo;
}
else
{
   echo 'Message has been sent.';
}

}


You're re-using the same message each time around the loop. Each time 
you call AddAddress you're, erm, adding another address. You either need 
to reset the recipients or reset the message each time round the loop 
(I'm not familiar with Phpmailer so I have no idea how to do this).


-Stut

--
http://stut.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP-DB] Phpmailer sending duplicate messages...

2007-11-01 Thread Instruct ICC

 You're re-using the same message each time around the loop. Each time 
 you call AddAddress you're, erm, adding another address. You either need 
 to reset the recipients or reset the message each time round the loop 
 (I'm not familiar with Phpmailer so I have no idea how to do this).
 
 -Stut

Stut is right.

If you put
$mail = new PHPMailer();
within the while loop, you should be okay.

_
Climb to the top of the charts!  Play Star Shuffle:  the word scramble 
challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_oct

RE: [PHP-DB] Phpmailer sending duplicate messages...

2007-11-01 Thread Instruct ICC

 Stut and Instruct
 
 Just found this which clears the email after each loop.
 
 $mail-ClearAddresses();
 
 Thanks for you input.

Good find.  Now the list can benefit.

_
Climb to the top of the charts!  Play Star Shuffle:  the word scramble 
challenge with star power.
http://club.live.com/star_shuffle.aspx?icid=starshuffle_wlmailtextlink_oct