我有一个“用户评论”数据库,其中包含评论、用户 ID、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 封电子邮件?如果以上内容还不够清楚,请告诉我。谢谢!!
最佳答案
我认为你可以添加一个groupby...
$ab->groupby('email');
选择后
关于php - 向检查过 'yes' - php 和 modx 的用户发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19034486/