php - 如何使用 php mailer 仅在 TO 地址上显示相关电子邮件
问题描述
使用 phpmailer 发送电子邮件时如何隐藏其他电子邮件?我收到来自数据库的电子邮件。该代码正在向所有人发送邮件,但在其显示所有电子邮件的标题上。请帮助我的代码如下:
$stmt = $conn->prepare("SELECT * FROM subscribers");
$stmt->execute();
$results= $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($results as $row){
$mail->addAddress($row['email']);
}
解决方案
您可以在循环中添加发送函数,但是这在大型数据集上是资源昂贵的。
$stmt = $conn->prepare("SELECT * FROM subscribers");
$stmt->execute();
$results= $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($results as $row){
$mail->addAddress($row['email']);
$mail->Send();
$mail->clearAddresses();
}
您也可以将此作为参考,以更有效地执行此操作
https://github.com/PHPMailer/PHPMailer/blob/master/examples/mailing_list.phps
正如KIKO Software
上面评论中提到的,如果电子邮件不是针对每个用户进行个性化的,那么您可以$mail->addBcc($row['email'])
在循环内使用并批量发送所有电子邮件。
// add a main email address
$mail->addAddress('an_email_here');
foreach($results as $row){
// then just bcc other emails.
$mail->addBcc($row['email'])
}
$mail->Send()
注意:这也会向用户显示电子邮件刚刚BCC
编辑
推荐阅读
- c - 如何在 C 中创建 2 个线程?
- python - 如何使用 SMOTE 将合成数据集保存在 CSV 文件中
- ssl - 如何将自签名证书分配给连接到 Intranet 域的所有用户?
- listview - Flutter - 使用 StreamBuilder 从 firebase 获取数据后,如何使用 ScrollController 跳转到列表视图的底部?
- python - 谷歌使用python在网页中翻译
- javascript - Typescript error :: Type 'number' is not assignable to type 'never'
- c# - 当返回的异常是“AggregateException”而不是“WebException”时如何获取Web响应异常流
- android - Android 房间数据库迁移运行多次
- postgresql - 如何在 logstash 配置文件中使用聚合过滤器?
- email - 一天服务调用次数过多:电子邮件