Björn C
Björn C

Reputation: 4008

Trying to send mail with PHP Mailer and BCC

I'm using the plugin "PHPMailer-master" to send email to adresses stored in my db.

I collect all adresses in a string:

$recipients = "[email protected];[email protected];[email protected]"; // OR
$recipients = "[email protected],[email protected],[email protected]";

Later i set BCC:

$mail->addBCC($recipients);

I also set my mail to get the mail:

$mail->addAddress('[email protected]');

So, i get no errors... but the only mail that is sent is the one to myself.. what can be the problem? How can i search what's wrong?

UPDATE

This is how i create my string:

while($row = $stmt->fetch()){
    $recipients .= $row['email'] . ";";
}

Upvotes: 1

Views: 769

Answers (1)

Luca Jung
Luca Jung

Reputation: 1440

You can not add the mails like this. The Documentation for AddBCC looks like this AddBCC($address, $name = "").
I recommend you to use foreach loop or something similar:

$recipientsArray = explode(";",$recipients); //The delimiter depends on your string that separated the emails
foreach($recipientsArray as $recipient) {
  $mail->addBCC($recipient);
}

Update (Regarding your update)

How you create the Array does not matter. The key point is that the PHPMailer function only accepts one BCC per call. If you fetch it, then you can do it like this:

while($row = $stmt->fetch()){
    $recipients[] = $row["email"];
}

Upvotes: 2

Related Questions