简体   繁体   English

如何使用 php 邮件在 TO 地址上仅显示相关的 email

[英]How to show only relevant email on TO Address using php mailer

How do I hide other emails when sending emails using phpmailer?使用 phpmailer 发送电子邮件时如何隐藏其他电子邮件? I'm getting emails from the database.我收到来自数据库的电子邮件。 The code is sending mails to all but on the headers on TO its showing all emails.该代码正在向所有人发送邮件,但在其显示所有电子邮件的标题上。 Please help my code is as follows:请帮助我的代码如下:

$stmt = $conn->prepare("SELECT * FROM subscribers");
$stmt->execute();
$results= $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($results as $row){
    $mail->addAddress($row['email']); 
}

You can add the send function inside the loop, however this is resource expensive on large datasets.您可以在循环内添加发送 function,但是这在大型数据集上是资源昂贵的。

$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();
}

You can also use this as a reference for a much more efficient way of doing this您也可以将此作为参考,以更有效地执行此操作

https://github.com/PHPMailer/PHPMailer/blob/master/examples/mailing_list.phps https://github.com/PHPMailer/PHPMailer/blob/master/examples/mailing_list.phps

As mention by KIKO Software from the comments above, if the email is not personalized for each users then you can use $mail->addBcc($row['email']) inside the loop and send all emails on bulk.正如KIKO Software从上面的评论中提到的,如果 email 不是针对每个用户个性化的,那么您可以在循环中使用$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()

Note: this will also appear to users that the emails are just BCC ed注意:这也会向用户显示电子邮件只是BCC ed

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

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