当学生在自学注册中使用注册代码注册课程时,如何向管理员发送电子邮件通知

时间:2017-07-19 12:45:05

标签: php moodle

当学生使用自助入学课程报名参加课程时,我需要向管理员发送电子邮件通知。

在PayPal中,有一个名为Notify admin的设置选项,此帮助向用户发送电子邮件通知,但在自我注册中我没有找到任何此类选项。

是否有一些设置要启用或我必须编写一些自定义代码,如果我必须编写代码来发送电子邮件通知,那么我在哪里可以编写这些代码。

请帮帮我。

2 个答案:

答案 0 :(得分:0)

您可以使用cron job并添加一些时间间隔来检查用户是否具有自我注册。如果用户有自助注册而不是调用另一个函数来发送邮件。

function checkuser(){ 
$total_time = 0;
$start_time = microtime(true);
while($total_time < 60)//run while less than a minute
 {
   checkFunction(); //DoSomething;
    sleep(20);   //wait amount in seconds
    $total_time =  microtime(true) - $start_time ;
  } 
}

function checkFunction(){
  //check user self enrollment here add into some variable
  // check if it is true than
  if($check == true){
     $to = 'nobody@example.com';
     $subject = 'the subject';
     $message = 'hello';
     $headers = 'From: webmaster@example.com' . "\r\n" .
     'Reply-To: webmaster@example.com' . "\r\n" .
      'X-Mailer: PHP/' . phpversion();
     mail($to, $subject, $message, $headers);
   } 
 }

答案 1 :(得分:0)

使用local plugin创建event observer,查找事件&#39; \ core \ event \ course_enrolment_created&#39;。

在处理程序功能中,检查$ event-&gt;其他[&#39; enroll&#39;]是否匹配&#39; self&#39; - 如果没有,请忽略该事件。如果匹配,则使用email_to_user()函数(或者更好的是,使用message API)向课程中的所有相关用户发送消息。