function mail_debugger_callback_valid_user_mail in Mail Debugger 7.2
Validate user mail
_state
Parameters
type $form:
1 string reference to 'mail_debugger_callback_valid_user_mail'
- mail_debugger_callback in includes/
mail_debugger.callback.inc - Callback for drupal_get_form
File
- includes/
mail_debugger.callback.inc, line 187
Code
function mail_debugger_callback_valid_user_mail($form, &$form_state) {
$user = user_load_by_mail($form_state['values']['user']['mail']);
$values = $form_state['values']['user'];
if (!$user) {
if (valid_email_address($values['mail'])) {
$test = explode('@', $values['mail'], 2);
$test = reset($test);
}
else {
$test = $values['mail'];
}
$query = db_like($test) . '%';
$result = db_select('users', 'u')
->fields('u')
->condition('mail', $query, 'like')
->condition('status', 1)
->orderBy('mail')
->range(0, 5)
->execute()
->fetchAll();
foreach ($result as $item) {
$didyoumean[] = $item->mail;
}
if (count($didyoumean) > 0) {
form_set_error('user][mail', t("Did you mean @alternatives?", array(
'@alternatives' => implode(', ', $didyoumean),
)));
}
else {
form_set_error("user][mail", t('This e-mail address does not match any user.'));
}
}
}