Reply to email validation (no regex)

Your name:

Reply:


Posted by Jim Moseby on 09/21/05 20:49

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@example.com".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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация