I have a rule to create a user and an action to send login url to user's email. I didn't find any action to send login url, so added an Send HTML Email action and added the [user-created:one-time-login-url] token in mail body. but it appears as it is([user-created:one-time-login-url]), and is not translated to login url.

Then I used this php function to print the same url:

print user_pass_reset_url($user_created); 

It prints a url but also prints the following notices:

Notice: Undefined property: stdClass::$uid in user_pass_reset_url() (in line 2299 /var/www/web/modules/user/user.module).
Notice: Undefined property: stdClass::$pass in user_pass_reset_url() (in line 2299 /var/www/web/modules/user/user.module).
Notice: Undefined property: stdClass::$login in user_pass_reset_url() (in line 2299 /var/www/web/modules/user/user.module).

$user_created is the php variable referring to the user created in the previous action. But it seems it's not a user object(because of notices).

What's the proper way to send one time login url?

  • 1
    If $user_created is the UID variable, you will need to load the user object like this: $user = user_load($user_created); Then you can use your other function like: user_pass_reset_url($user);
    – Mike
    Mar 1, 2013 at 8:06
  • tried that but this time I get some fatal errors
    – Nima
    Mar 1, 2013 at 11:05

3 Answers 3


Try out Login one time module

The use case for this is where your users can't figure out how to use a username and password - so they request an email link to what they need.

  • using this module with recipient user field set to user-created value still prints the same notices.
    – Nima
    Mar 1, 2013 at 11:05

You need to use the token_replace function like this

$newly_created_user = user_load(101);
$subject =token_replace('Hello  [user:field-your-first-name]  [user:field-your-last-name], here is your password reset link [user:one-time-login-url] ', array('user' => $newly_created_user), array('callback' => 'user_mail_tokens', 'sanitize' => FALSE));

ultimately you need to add extra third parameter to the token_replace function

array('callback' => 'user_mail_tokens', 'sanitize' => FALSE)

The solution was adding an Save entity action before using user_pass_reset_url() function or login one time action.

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.