1

I am using PHPMailer and use AddBCC to send to most of my addresses (only use 1 required in AddAddress). It seems to work okay (no errors), but I have found that it isn't saving (or sending to) all of the addresses that I process with $mail->AddBCC. It skips some of them, yet keeps others. So, when I do a print_r($mail->getBccAddresses()), I can see that it only has some of the email addresses. I am processing my lists of addresses in small groups, so I can control things better, so I wouldn't think there'd be any problems like this. I am including the applicable code from my program:

<?php session_start();

require '../PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;

$emailist_cnt = 3;

    for ($i=1; $i<= $emailist_cnt; $i++) {
      //loop to gather email addresses into array $emailistAry[][]
    }

    // First, set up email message and required parameters.
    $toname = "Grp-members";// Unused mailbox name
    $fromname = "Webmaster";  
    $replyname ="Grpwebmaster";  
        $fromaddr = $fromname."@mydomain.org";
    $toaddr = $toname."@mydomain.org";
    $rplyaddr = $replyname."@gmail".".com";

    $subject = "-- Website Update--";
    $note1 = "New content has been added to the website";
    $note2 = "Go check it out, if you want to stay up-to-date:";
    $message = "Greetings HLCA Member! ".$note1." ".$note2;

    // Set mail environment variables
    $mail->isSMTP();                                    
    $mail->Host = 'smtp.hiddenlakeonline.org';          
    $mail->SMTPAuth = true;                             
    $mail->Username = $fromname."@".$domain.".org";    
    $mail->Password = $webpass;                         
    $mail->SMTPSecure = 'tls';                          
    $mail->Port = 587;                                  

    // Set mail details that remain constant for every recipient
       $mail->SetFrom($fromaddr);      
       $mail->AddAddress($toaddr);    
       $mail->AddReplyTo($rplyaddr);  
           $mail->Subject = $subject;
       $mail->Body    = $message;

       $max_emails = 25; // max num emails per list  

    for ($i=1; $i <= $emailist_cnt; $i+=1) { 

           for ($j=1; $j <= $max_emails; $j+=1) {                  
              // Addresses in current list will be added to BCC param.  
      if ($emailistAry[$i][$j] != '') {
             $mail->AddBCC($emailistAry[$i][$j]); // add email to BCC                 }
       } // for j loop

           echo "would send to email list here. ";
       print_r($mail->getBccAddresses()); 

       // Clear cumulative recipient list for next loop
       $mail->clearBCCs();

    } // for i loop
 ?>  

As you can see, I'm just doing a loop to add BCC entries. But, when I print out the getBCCaddresses array, there is always at least one email missing from each list. Is there a bug in PHP Mailer? Or am I doing something wrong?

I have seen a similar post (without any code) on another site (sourceforge.net?), but the question never got answered. Otherwise, there hasn't been anything similar that could help. Hopefully someone on here knows something about this.

Here are some results I get using echo outputs:
i,j,adding this email: 1,1,ImxEarth@gmail.com i,j,adding this email: 1,2,heffxdog@me.com i,j,adding this email: 1,3,imxearth@gmail.com i,j,adding this email: 1,4,Aaronx72@yahoo.com

print: Array ( [0] => Array ( [0] => ImForEarth@gmail.com [1] => ) [1] => Array ( [0] => heffdog@me.com [1] => ) [2] => Array ( [0] => AaronTW72@yahoo.com [1]  => ) )                                                                                                           

Is it possible that phpMailer prevents duplicate addresses in BCC array?

  • Here is some output I get using some echo output: i,j,adding this email: 2,1,hlcawebmaster@gmail.com i,j,adding this email: 2,2,psy.jennifer@gmail.com i,j,adding this email: 2,3,heffdog@me.com i,j,adding this email: 2,4,hlcawebmaster@gmail.com would send email list here. BCC list = psy.jennifer@gmail.com,heffdog@me.com,, bcc print: Array ( [0] => Array ( [0] => hlcawebmaster@gmail.com [1] => ) [1] => Array ( [0] => psy.jennifer@gmail.com [1] => ) [2] => Array ( [0] => heffdog@me.com [1] => ) ) – user2735375 Mar 20 '16 at 16:36
  • You are not checking return values from `addBCCAddress`, so you're not seeing when it rejects invalid addresses. – Synchro Mar 20 '16 at 17:25
  • And yes, PHPMailer does skip duplicate addresses. – Synchro Mar 20 '16 at 17:26

1 Answers1

1

I think I found my answer! It appears that AddBCC will only add unique email addresses to its array. So if an email address already exists in the BCCaddresses array, then the Mail->AddBCC('email') statement will not add it again. This becomes apparent when testing, because we often need to use duplicates to create a good size batch of emails. Well, you can process the duplicates, but they won't be added to the BCC parameter and won't be mailed more than once. Thx to all that responded!