gpt4 book ai didi

drupal - 以编程方式创建 Drupal 用户时如何发送电子邮件通知?

转载 作者:行者123 更新时间:2023-12-04 13:02:54 24 4
gpt4 key购买 nike

我正在尝试使用代码创建用户。我有以下创建用户的内容。但是,它不会向用户发送一封电子邮件,说明该帐户已创建。我怎样才能做到这一点?

$newUser = array(
'name' => 'username',
'pass' => 'password', // note: do not md5 the password
'mail' => 'email address',
'status' => 1,
'init' => 'email address'
);
user_save(null, $newUser);

最佳答案

您可以使用标准 _user_mail_notify() Drupal 核心的“用户”模块中的函数。

   // Create user.
$new_user = array(
'name' => $username,
'pass' => $password,
'mail' => $email,
'status' => 1,
'init' => $email,
'roles' => array(DRUPAL_AUTHENTICATED_RID => TRUE),
);
$account = user_save(NULL, $new_user);
// Set operation.
$op = 'register_no_approval_required';
// Send an email.
_user_mail_notify($op, $account);

$op 有不同的值:
 /* @param $op
* The operation being performed on the account. Possible values:
* - 'register_admin_created': Welcome message for user created by the admin.
* - 'register_no_approval_required': Welcome message when user
* self-registers.
* - 'register_pending_approval': Welcome message, user pending admin
* approval.
* - 'password_reset': Password recovery request.
* - 'status_activated': Account activated.
* - 'status_blocked': Account blocked.
* - 'cancel_confirm': Account cancellation request.
* - 'status_canceled': Account canceled.*/

关于drupal - 以编程方式创建 Drupal 用户时如何发送电子邮件通知?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4247405/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com