function rules_action_user_send_account_email

Action: Send a user account e-mail.

Related topics

1 string reference to 'rules_action_user_send_account_email'
rules_user_action_info in modules/user.rules.inc
Implements hook_rules_action_info() on behalf of the user module.

File

modules/user.eval.inc, line 104

Code

function rules_action_user_send_account_email($account, $email_type) {
    // If we received an authenticated user account...
    if (!empty($account->uid)) {
        module_load_include('inc', 'rules', 'modules/user.rules');
        $types = rules_user_account_email_options_list();
        // Attempt to send the account e-mail.
        // This code is adapted from _user_mail_notify().
        $params = array(
            'account' => $account,
        );
        $language = user_preferred_language($account);
        $mail = drupal_mail('user', $email_type, $account->mail, $language, $params);
        if ($email_type == 'register_pending_approval') {
            // If a user registered requiring admin approval, notify the admin, too.
            // We use the site default language for this.
            drupal_mail('user', 'register_pending_approval_admin', variable_get('site_mail', ini_get('sendmail_from')), language_default(), $params);
        }
        $result = empty($mail) ? NULL : $mail['result'];
        // Log the success or failure.
        if ($result) {
            watchdog('rules', '%type e-mail sent to %recipient.', array(
                '%type' => $types[$email_type],
                '%recipient' => $account->mail,
            ));
        }
        else {
            watchdog('rules', 'Failed to send %type e-mail to %recipient.', array(
                '%type' => $types[$email_type],
                '%recipient' => $account->mail,
            ));
        }
    }
}