Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Email Verification....

Status
Not open for further replies.

chromonium

Programmer
Jun 4, 2002
36
FR
Dear Experts,

I have found a free script on the net to detect whether a specified email address is valid....

How it is missing some things:

Character check,
and splitting of the original email address into $host and $user,

Your Help would be most appreciated in regards to this matter:

this is the code..:

<?PHP
class CEmail{

function check($host,$user){

$fp = fsockopen ($host, 25);
set_socket_blocking ($fp, true);
fputs ($fp, &quot;Helo Local\n&quot;);
fgets ($fp, 2000);
fgets ($fp, 2000);
fputs ($fp, &quot;Mail From:<$user@$host> \n&quot;);
fgets ($fp, 2000);
fputs ($fp, &quot;RCPT to:aetos<$user@$host> \n&quot;);
$result= fgets ($fp, 2000);
$st= substr($result,0,3);
if ($st==250){

echo&quot;Email address is valid&quot;;
}

else
echo&quot;The address is not valid&quot;;

}
}

$m=new CEmail;
$m->check(&quot;acvilon.com&quot;,&quot;farkon&quot;);

?>

But this requires a valid host in the first place. Without a valid host the script returns errors. How can these errors be turned into a controlled response, ie return false so that the script returns that the email address cannot exist.

In addition to this the $host address seems to be in both and How can both of these versions of URL be tested, ie input is hello.com, and the script checks both versions, controlling errors.

Many Regards

Adam
 
But his sample isn't checking for a well formed email address... it's actually busting into the persons email server and generating an email, and seeing if the user exists on that host... it's a step you'd take after checking it was well formed.

I'm guessing though, that plenty of security systems would stop it from working... this takes advantage of ports that as far as I'm aware are usually closed to such access.

(Remembering having to spoof email for my networking class a couple years back... this looks very similar... so I'm not sure if it really will kick back a problem for a non-existant user anyway... have you tested this with any success?)

-Rob
 
Check first that the address is well-formed.

Then check that an MX record is defined for the domain. See getmxrr() (
Then check that the MX host is resolvable. For this, I would use gethostbyname() (
Then I would perform the checks in the code sample above. Want the best answers? Ask the best questions: TANSTAAFL!
 
skiflyer

yes, i tried that code but doesn't work. it seems the port number 25 is closed from access. so, i could i get around this problem since i really want to check the existing of the user instead of just check its well-formatting and the validity of the domain.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top