Working with the user.module of 4.5.2 distribution I amended the user_validate_mail() function to provide additional checking for a new user.

This was inspired by the constant bounced emails I was getting each day from new users mistyping their email address.

Sorry that the code is not in patch form. The following code should be placed in user.module :-

function _user_check_dnsrr($maildomain, $rectype = 'MX')
{
  if(!empty($maildomain)) {
    if(function_exists('checkdnsrr')) {
      return checkdnsrr($maildomain, $rectype);
    } else {
      exec("nslookup -type=$rectype $maildomain", $result);
      foreach ($result as $line) {
        if(eregi("^$maildomain",$line)) {
          return true;
        }
      }

      return false;
    }
  }

  return false;
}

function user_validate_mail($mail) {
  if (!$mail) return t('You must enter an e-mail address.');

  list($username, $maildomain) = split("@", $mail);

  if (!valid_email_address($mail) || !_user_check_dnsrr($maildomain, "MX")) {
    return t('The e-mail address %mail is not valid.', array('%mail' => "<em>$mail</em>"));
  }
}

I have been using the above on http://www.bargainspy.co.uk/user/register without problem for a day now. Another step in the direction of helping users hide their general stupidity!

Comments

budda’s picture

it may be more helpful to move the MX record checking in to the common valid_email_address() function instead? This would ensure other modules validating email addresses could gain the same functionality.

dries’s picture

This is not a patch and not against CVS.