Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Problem with emails being sent twice with PHPMailer



Hi All,

I am very frustrated. I have a simple (at least I think it is) script that pulls email addresses, populates a text file and sends it out. BUT it is sending the email TWICE! I am not an experienced php/mysql person and using phpmailer has been great up until now, but I think everything is correct. If some one has an idea of why it's sending the message twice, that would be great. Is this a phpmailer problem or something else? Here are the stats.

The email list is about 2,600 people. As mentioned before, this problem is only a recent one. The list has been growing steadily. The emails are received not at the same time, but about 15 - 20 or so minutes apart from each other. This makes me think the script is running twice. I've been using this for some time and have only recently had this problem. I did a test with this script sending to a smaller database - 20 email addresses - and had no problems. Could it be the size of the list? Could the browser call the script again, for some reason, part of the way through? Is there a setting in phpmailer I am missing to set something so it won't send twice? Has this something to to with something timing out?

I'm completely at a loss. Any help would be greatly appreciated.

Thanks,

Mark

---------------------------------------------------------
Below is the script
---------------------------------------------------------

<?php
require_once ('../templates/login.php');
require ('../lib/phpmailer/class.phpmailer.php');

$email_errors = 0;
$error_flag = 0;
$error_array = array();
$subject = "Subject Goes Here";

$ic_text = file_get_contents("text_email.txt");

// Send the email

$mail = new PHPMailer();

$mail->From     = "email@hidden";
$mail->FromName = "Business Name";

$email_address_query  = "SELECT email_id, email, email_unique_id FROM email_list GROUP BY email ORDER BY email_id";
$email_address_result = mysql_query($email_address_query);

while ($email_address_row = mysql_fetch_array($email_address_result, MYSQL_ASSOC)) {
$ic_text_final = str_replace("<<EMAIL_ID>>", $email_address_row['email_unique_id'], $ic_text);
$ic_text_final = str_replace("<<YEAR>>", date("Y"), $ic_text_final);
$ic_text_final = str_replace("<<EMAIL>>", $email_address_row['email'], $ic_text_final);
$mail->Subject = $subject;
$mail->Body    = $ic_text_final;
$mail->AddAddress($email_address_row["email"]);

if(!$mail->Send()) {
  $error_flag = 1;

  $email_errors++;// Add 1 to $email_errors so that it comes up with the correct number of emails NOT sent.
  $error_array[] = $email_address_row['email'].' - '.$email_address_row['email_id'];
}
// Clear all addresses for next loop.
$mail->ClearAddresses();
// Write the email_id and incremented number back to the tracking table.
$count++;
}

if ($error_flag == 0) {
echo "No Errors.<br><br>\n";
} else {
echo $email_errors."error(s) occured.<br><br>\n";
for ($i=0; $i<count($error_array); $i++) {
  echo $error_array[$i]."<br>\n";
}
}

echo "Email sent.";
exit;
?>
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Web-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/web-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.