RE: [PHP-DB] Phpmailer sending duplicate messages...
| From: | Instruct ICC | Date: | Thu, 01 Nov 2007 20:41:50 +0000 |
| Subject: | RE: [PHP-DB] Phpmailer sending duplicate messages... | ||
| References: | 1 2 3 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-44290@lists.php.net to get a copy of this message | ||
> while($row = mysqli_fetch_assoc($result))
> {
> extract($row);
>
> $mail->IsSMTP();
> $mail->Host = "host.com";
> $mail->From = "info@host.com";
>
> $mail->From = "info@host.com";
> $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 =
"arr[]=user1@example.com&arr[]=user2@example.com&arr[]=user3@example.com";
parse_str($recipients);
for($i=0; $i<count($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