注册后发送电子邮件用户数据 [英] Email moodle user data after registration

查看:195
本文介绍了注册后发送电子邮件用户数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的moodle网站上注册用户后向管理员发送一封自定义的电子邮件,但是我希望它能显示所有的用户号码,我一直在搜索很多,并发现这个链接,它会向使用者名称的管理员发送一封自定义的电子邮件,但是我本来试图发送更多的信息,如我添加的自定义字段,甚至默认的字段,如手机,但我找不到方法,我希望你帮助我。

i need to send a custom email to the admin after user registration on my moodle site, but i want it to have all the user iformation displayed, i been searching a lot and found this link, it sends a custom email to the admin with the user name, but i've ben trying to send more info like custom fields added by me or even default fields like the phone but i can't find a way, i hope u help me.

推荐答案

您可以使用'user_created'事件。
http://docs.moodle.org/dev/Events_API#Users

You could use the 'user_created' event. http://docs.moodle.org/dev/Events_API#Users

没有测试过,但您可以创建本地插件

Haven't tested this but you could create a local plugin

创建本地文件夹

/local/newuser/

创建events.php

Create events.php

/local/newuser/db/events.php

将其粘贴到events.php中

Paste this into events.php

defined('MOODLE_INTERNAL') || die();

$handlers = array (
    'user_created' => array (
        'handlerfile'      => '/local/newuser/lib.php',
        'handlerfunction'  => 'local_newuser_user_created',
        'schedule'         => 'instant',
    ),
);

创建一个lib.php文件

Create a lib.php file

/local/newuser/lib.php

将其粘贴到lib .php

Paste this into lib.php

defined('MOODLE_INTERNAL') || die();

function local_newuser_user_created($user) {
    global $DB;

    $body = '';

    // Original fields.
    foreach ($user as $field => $value) {
        $body .= $field . ' = ' . $value . "\n";
    }

    // Custom fields.
    $sql = "SELECT f.id, f.name, d.data
            FROM {user_info_field} f
            LEFT JOIN {user_info_data} d ON d.fieldid = f.id AND d.userid = :userid";
    $customfields = $DB->get_records_sql($sql, array('userid' => $user->id);
    foreach ($customfields as $customfield) {
        $body .= $customfield->name . ' = ' . $customfield->data . "\n";
    }

    // Send the email to the admin user
    $admin = get_admin();
    $subject = get_string('newuser');
    email_to_user($admin, $admin, $subject, $body);

    return true;
}

最后创建一个version.php

Finally create a version.php

/local/newuser/version.php

并粘贴此

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2014012901; // Plugin version.
$plugin->requires = 2013051402; // Moodle version.
$plugin->component = 'local_newuser'; // Full name of the plugin (used for diagnostics).

然后在Moodle中转到站点管理 - >不添加代码的分数。然后创建一个用户,管理员应该收到一封电子邮件:)

Then in Moodle go to site admin -> notifications to add the code. Then create a user and the admin should receive an email :)

这篇关于注册后发送电子邮件用户数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆