多次向同一用户发送相同的电子邮件

时间:2019-03-07 11:19:03

标签: php

当管理员创建新事件时,我正在尝试将电子邮件发布给用户。电子邮件正在触发,但是学生多次收到相同的电子邮件。我在代码中使用了每个。任何帮助表示赞赏。

   $this->properties->id = $DB->insert_record('event', $this->properties);
   $tooo = $DB->get_record('role', array('shortname' => 'student'));
   $too =  $DB->get_records('role_assignments', array('roleid' => $tooo->id));
   $pageNos = array();
   foreach($too as $new)
   {
      $t = $DB->get_record('user', array('id' => $new->userid));
       // if(!in_array($t,$pageNos)){
      $body = "event has been posted by {$USER->username} : {$content} on student assignment "; 
      email_to_user($t,$USER,'event Notification ','The text of the message',$body);
   }

1 个答案:

答案 0 :(得分:-1)

您可以尝试这样

$this->properties->id = $DB->insert_record('event', $this->properties);
$tooo = $DB->get_record('role', array('shortname' => 'student'));
$too =  $DB->get_records('role_assignments', array('roleid' => $tooo->id));
$pageNos = array();
foreach($too as $new)
{
   if(!in_array($new->userid,$pageNos))
   {
     $t = $DB->get_record('user', array('id' => $new->userid));
     $body = "event has been posted by {$USER->username} : {$content} on student assignment "; 
     email_to_user($t,$USER,'event Notification ','The text of the message',$body);
     $pageNos[] = $new->userid;
   }
}
相关问题