dongyan7876 2015-06-17 13:26
浏览 65
已采纳

Moodle电子邮件功能不起作用

Hi i want to send an email as soon as record is inserted in moodle database table, following code is not working

if ($recs = $ti_form->get_data()) {
    // Do something with the data, then redirect to a new page
    $lastinsertid = $DB->insert_record('suggestions', $recs);
    $toUser = 'omerzia@live.com';
    $fromUser = 'ICAN';
    $subject = 'New Suggestion Added';
    $messageText = 'New Suggestion Added';
    $sent = email_to_user($toUser, $fromUser, $subject, $messageText);
    //mail($to, $subject, $message, $headers);

    if($sent) {
      print "Email successfully sent";
    }else{
      print "There was an error sending the mail";
     }

       redirect('suggestions.php');
}

Above code givers error message. What could be the reason? Any help much appreciated.

Thanks

  • 写回答

2条回答 默认 最新

  • dsla94915 2015-06-17 13:58
    关注

    If you look at the phpdoc header for the email_to_user() function, the first 2 parameters should be user objects rather than strings.

    * @param stdClass $user  A {@link $USER} object
    * @param stdClass $from A {@link $USER} object
    

    So for the to user

    $touser = $DB->get_record('user', array('email' => 'omerzia@live.com');
    

    For the from user you could use the support user

    $fromuser = core_user::get_support_user();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入