2

I am very new in Drupal. I have an installation of Drupal 7 with LDAP authentication and LDAP user provision, this LDAP is linked to corporate mail system too. Users have 2 mail accounts (a corporate account and an alternative account), if a user forgot his password, I need the password reset send mail to both email addresses not only to the corporate account.

1 Answer 1

4

You'll want to create a custom module, please see https://www.drupal.org/node/1074360

You can then implement hook_mail_alter().

/**
 * Implements hook_mail_alter().
 */
function my_module_mail_alter(&$message) {
  // Alter password reset
  if ($message['id'] == 'user_password_reset') {
    // Load the user by email address
    if ($user = user_load_by_mail($message['to'])) {
      // If you have another user field with their alternative email address, add to the $message array
      if (!empty($user->field_user_alt_mail)) {
        $message['to'] = $message['to'] . ', ' . $user->field_user_alt_mail[LANGUAGE_NONE][0]['value'];
      }
    }
  }
}

edit: changed 'password_reset' to 'user_password_reset' as per Paul's comment.

1
  • Please note, that $message['id'] is actually user_password_reset. Alternatively, you can check $message['key'] which is password_reset. Additionally, if an email field is used (instead of a simple text field), you need to call $user->field_user_alt_mail[LANGUAGE_NONE][0]['email'] (it's email instead of value).
    – Paul
    Commented Sep 17, 2015 at 13:21

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.