3

I can't seem to find documentation for notifying a user via email after their account has been created by a script.

$user = \Drupal\user\Entity\User::create();

$user->setPassword('xxx');
$user->enforceIsNew();
$user->setEmail('xxx+'.time().'@gmail.com');
$user->setUsername('xxx'.time());

$user->set('init', 'email');
$user->set('langcode', $language);
$user->set('preferred_langcode', $language);
$user->set('preferred_admin_langcode', $language);
$user->activate();

//$user->notify()? something?

$result = $user->save();
1
  • 1
    This is set under /admin/config/people/accounts.
    – user72672
    Oct 31, 2019 at 14:33

1 Answer 1

2

You can find the configuration on admin in the /admin/config/people/accounts but if you want to notify the user programmatically without taking care of what is the config you can use _user_mail_notify function.

_user_mail_notify documentation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.