简体   繁体   English

尝试使用PHP Mailer和BCC发送邮件

[英]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. 我正在使用插件“ PHPMailer-master”将电子邮件发送到存储在数据库中的地址。

I collect all adresses in a string: 我将所有地址以字符串形式收集:

$recipients = "mail@mail.com;mail@mail.com;mail@mail.com"; // OR
$recipients = "mail@mail.com,mail@mail.com,mail@mail.com";

Later i set BCC: 后来我设置了密件抄送:

$mail->addBCC($recipients);

I also set my mail to get the mail: 我还设置了我的邮件以获取邮件:

$mail->addAddress('my@mail.com');

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 UPDATE

This is how i create my string: 这是我创建字符串的方式:

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

You can not add the mails like this. 您不能添加这样的邮件。 The Documentation for AddBCC looks like this AddBCC($address, $name = "") . AddBCC的文档如下所示: AddBCC($address, $name = "")
I recommend you to use foreach loop or something similar: 我建议您使用foreach循环或类似的方法:

$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. 关键是PHPMailer函数每次调用仅接受一个BCC。 If you fetch it, then you can do it like this: 如果获取它,则可以这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM