email validation (no regex)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I threw together this totally untested and unreliable code to solicit
comments on whether or not this is a good way to validate emails.  Consider
the following:

<pseudocode>

function validate_email($email){
  if (str_word_count($email,'@')!=1){return('Not a proper email address');}
  $parts=explode('@',$email);
  $name=$parts[0];
  $domain=$parts[1];
  $mxconnect=FALSE;
  if (!getmxrr($domain,$mxhosts)){
    return('Invalid domain');
  }//if
  foreach($mxhosts as $mxhost){
    if($fp=fsockopen($mxhost,25)){
      $mxconnect=TRUE;
      fwrite($fp,"EHLO test");
      $response=fread($fp,256);
      fwrite($fp, "Mail From: jim@xxxxxxxxxxx".chr(13));
      $response=fread($fp,256);
      fwrite($fp, 'RCPT To: '.$email.chr(13));
      $response=fread($fp,256);
      $parts=explode(' ',$response);
      if ($parts[0]!='250'){
        fwrite($fp,'QUIT'.chr(13));
        fclose($fp);
        return('Unknown Recipient');
      }//if
    }//if
  }//foreach
  if (!$mxconnect){return('Could not connect to MX');}
  fwrite($fp,'QUIT'.chr(13));
  fclose($fp);
  return('OK');
}//function validate_email

</pseudocode>

So, what is the general thought about validating email addresses in this
manner?

JM

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux