Posted: Tue Jul 12, 2005 11:26 pm
Amazing Roja! Nice work. Thanks!
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Well here is what the backend does. Try it! It uses fsockopen to contact the remote mail server.Roja wrote:So which method are you using to ask it that? VRFY?
Nice script. Haven't had a proper look at the code, but do you use Ajax?bokehman wrote:Well here is what the backend does. Try it! It uses fsockopen to contact the remote mail server.Roja wrote:So which method are you using to ask it that? VRFY?
You didn't answer the question at all. You just posted another link to another script that also doesn't show what method it uses.bokehman wrote:Well here is what the backend does. Try it! It uses fsockopen to contact the remote mail server.Roja wrote:So which method are you using to ask it that? VRFY?
Let me specify: did you use any particular library?bokehman wrote:XMLHttpRequest object == Microsoft.XMLHTTP == AJAX
All pretty much different names for the same function.
How right you are. It means something slightly different in the context of programming.bokehman wrote:I'm not sure what you mean by library. Isn't that a place from which you borrow books?
No! I just connect to the remote mail server and send (amongst other things):Roja wrote:So which method are you using to ask it that? VRFY?bokehman wrote:This is nothing to do with REGEX. It is a real time connection with the remote mail server to see if it will accept mail for an address it has authority for.
Can you share the code, or list all the commands you use?bokehman wrote:I just connect to the remote mail server and send (amongst other things)
Of course. I'm assuming you mean my PHP code!Roja wrote:Can you share the code, or list all the commands you use?
Code: Select all
function check_email_address_exists($email)
{
$result = true;
// Extract the mail server name from the email address.
list ($user, $domain) = split ("@", $email);
if (getmxrr($domain, $mxhost)){
$ConnectAddress = $mxhost[0];
}else{
$ConnectAddress = $domain;
}
if(gethostbynamel($ConnectAddress) === FALSE){
return FALSE;
}
// Try to open a socket at the mail server address.
if($ConnectAddress == $domain){
$connect = @fsockopen($ConnectAddress, 25, $errno, $errstr, 5);
}else{
$tries = count($mxhost);
$i = 0;
$connect = @fsockopen($mxhost[$i], 25, $errno, $errstr, 5);
while(!$connect && !$tries == 0){
$i++;
$connect = @fsockopen($mxhost[$i], 25, $errno, $errstr, 5);
$tries--;
}
}
if ($connect)
{
if (ereg("^220", $out = fgets($connect, 1024)))
{
while(ereg('220', $out)){
$debug[] = 'Remote: '.$out;
stream_set_timeout($connect, 0, 5000);
$out = fgets ( $connect, 1024 );
stream_set_timeout($connect, 10);
}
$debug[] = "Local: EHLO {$_SERVER['HTTP_HOST']}";
fputs ($connect, "EHLO {$_SERVER['HTTP_HOST']}\r\n");
$out = fgets ( $connect, 1024 );
while(!ereg('^250', $out)&&(!empty($out))){
$debug[] = 'Remote: '.$out;
stream_set_timeout($connect, 0, 5000);
$out = fgets ( $connect, 1024 );
stream_set_timeout($connect, 10);
}
for($tries = 15; $tries > 0; $tries--){
if(ereg('^250', $out)){
$debug[] = 'Remote: '.$out;
$for_loop_hop = $out;
}elseif(empty($out)){
usleep(100000);
}else{
$debug[] = 'Remote: '.$out;
}
stream_set_timeout($connect, 0, 5000);
$out = fgets($connect, 1024);
stream_set_timeout($connect, 10);
}
if(!ereg('^250', $for_loop_hop)){
$debug[] = 'No 250';
if(isset($_GET['debug'])){
foreach($debug as $line){
echo $line.'<br>';
}
}
return FALSE;
}
$debug[] = htmlspecialchars("Local: MAIL FROM: <{$email}>\r\n");
fputs ($connect, "MAIL FROM: <{$email}>\r\n");
$from = fgets ( $connect, 1024 );
$debug[] = 'Remote: '.$from;
$debug[] = htmlspecialchars("Local: RCPT TO: <{$email}>\r\n");
fputs ($connect, "RCPT TO: <{$email}>\r\n");
$to = fgets ($connect, 1024);
$debug[] = 'Remote: '.$to;
$debug[] = "Local: QUIT\r\n";
fputs ($connect, "QUIT\r\n");
$quit = fgets ($connect, 1024);
$debug[] = 'Remote: '.$quit;
fclose($connect);
// Validate our exchange with the mail server.
// Server rejected address.
if (!ereg ("^250", $from) || !ereg ("^250", $to))
{
$result = false;
}
}
// Strange or no response from remote mail server.
else
{
$result = false;
}
}
// Can't connect to server.
else
{
$result = 'Failed to connect to remote mail server';
}
if(isset($_GET['debug'])){
if($debug > 0){
foreach($debug as $line){
print "$line <br />\r\n";
}
}
}
return $result;
}