HI,

Thats beacuse of your code. See the while loop in your code



 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'];
 }


You are sending the mail in while loop and clearing the addresses outside the 
while loop. It will be cleared only after looping the while loop. At that it 
may send many mails.

To avoid it,  
add the line  $mail->ClearAddresses(); inside the if statement in while loop

 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'];
  }
  


By
Girish.

Mark Wheeler <[EMAIL PROTECTED]> wrote:                                  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, but I think everything is correct. If some one has an idea of  
 why it's sending the message twice, that would be great. Here are the  
 stats.
 
 The email list is about 2,600 people. The emails are received not at  
 the same time, but about 15 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?
 
 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 PROTECTED]";
 $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;
 ?>
 
     
                       

 
---------------------------------
Sponsored Link

   Mortgage rates as low as 4.625% - $150,000 loan for $579 a month. 
Intro-*Terms

[Non-text portions of this message have been removed]


Reply via email to