I'm implementing a function that send the password to users who forgot it.

This is the code I developed so far.

function my_module_lost_password($email) {
  global $language;

  $response = array();
  $account = user_load_by_mail($email);
  $params = array(
    'subject' => "hi",
    'body' => "hello",
  $from = "[email protected]";
  $to = $email;
 drupal_mail("???", "???", $to, $language, $params, $from); 


This function is called by a POST query (web service).

How do I use drupal_mail() to send a mail to users containing the password from the users table?

  • This resource is available already in the Services module: drupal.stackexchange.com/a/148826/10645 Aug 27, 2015 at 13:02
  • Hi tyler, yes it's available, but in my case i don't want to re-create a new password i want to send the existent password of the user who lost it by email, after loading all information by email
    – Mitch
    Aug 27, 2015 at 13:13
  • 1
    It's just impossible, now i understood that even if i can (it is now working) the password i send is hashed, so user cannot use it to login. so i don't have choice except storing text passwords
    – Mitch
    Aug 27, 2015 at 13:16

1 Answer 1


First thing, you cannot send the password. You can only send a reset/one-time-login link. Passwords in Drupal are a one-way street, they can never be retrieved. To send the link is pretty easy. Use _user_mail_notify()

_user_mail_notify('password_reset', $account);
  • Hi Brady and thak you for your help. Yes i know i've tested the _user_mail_notify it works, but imagine i want to send a mail to a user and this mails contains his username or just a simple (useless) information such as his uid or language (any thing from the table users). how can i user the function : drupal_mail and the message is just a simple information
    – Mitch
    Aug 27, 2015 at 10:42
  • To accomplish that. You would gather the data you want from the user table, then use hook_mail_alter to alter the password reset mail to your desires.
    – Brady
    Aug 27, 2015 at 10:47

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.