向选中“是”的用户发送电子邮件 - php 和 modx


Send email to users that checked 'yes' - php and modx

我有一个"用户评论"数据库,其中包含评论,userId,如果他们想通过电子邮件发送,则为true/false。

我的问题是,如果用户对帖子发表评论 5 次,他们在该数据库中 5 次,因此,他们会收到 5 封相同的电子邮件。这是我的设置:

在数据库中查找希望通过电子邮件发送有关此评论的用户

$ab = $modx->newQuery('Comments');
$ab->leftJoin('modUserProfile','Profile',array('Profile.internalKey = Comments.author'));
$ab->leftJoin('Bulletin','Bulletin',array('Bulletin.id = Comments.bulletin_id'));
$ab->where(array('Comments.bulletin_id' => $bullId));
$ab->where(array('Comments.email' => 1));
$ab->select(array('Comments.*','Profile.fullname as fullname' , 'Profile.email as email' , 'Bulletin.title as title'));
$emailList = $modx->getCollection('Comments',$ab);

现在,给他们发电子邮件

foreach ($emailList as $e){
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->address('to',$e->email);
$modx->mail->set(modMail::MAIL_BODY,$message);
$modx->mail->set(modMail::MAIL_SUBJECT,'A new comment has been posted!');}

我应该使用什么来向用户发送电子邮件,以便他们只收到 1 封电子邮件,无论他们发表的评论数量如何?如果以上内容不够清楚,请告诉我。谢谢!!

我认为您可以添加一个分组....

$ab->groupby('email'); 

在您选择之后