Programmatically submit user reset password form I have a register form that I am able to submit programmatically without any problems.

However when I try to do the same with the user reset password form, it doesn't send me any emails, nor does it do any validation.

Here's the code I'm using:

$form_state = array();
$form_state['values']['name'] = $_POST['username'];
$form_state['values']['submit'] = t('E-mail me new password');

drupal_form_submit('user_pass_form', $form_state);


Note: I've tried using user_pass instead of user_pass_form.

What am I doing wrong?
An alternative approach is this:

global $language;
$account = user_load_by_name($username);
if ($account) {
// Mail one time login URL and instructions using current language.
$mail = _user_mail_notify('password_reset', $account, $language);
  if (!empty($mail)) {
    watchdog('user', 'Password reset instructions mailed to %name at %email.', array('%name' =&gt; $account-&gt;name, '%email' =&gt; $account-&gt;mail));
  }
}


Essentially all you need is:

_user_mail_notify('password_reset', $account, $language);


More info: user_pass_submit