Jump to content

fsocketopen and e-mail verrification


Errant_Shadow

Recommended Posts

My question is not now to verify an e-mail address; I've got most of that down. My question is regarding fsocketopen, and communicating with a mail server.

 

Basically, the script I'm designing will run a series of tests to verify that a given e-mail address meets all of the syntax requirements it needs to, then it checks the domain name, finds the mail server, and makes sure the given address is actually registered.

 

The problem I'm having is with opening the socket. I keep getting a connection refused error (No 111). Since then I switched to udp protocol and it's not giving me the error, but I think its still not connecting. I can't actually get anything from it with either fread() or fgets().

 

this is what I got:

$emailDomain = "google.com"; // the domain I'm testing against
$dnsr = dns_get_record($emailDomain, DNS_MX); // fetch the DNS records for mail exchange servers

if (count($dnsr) < 1)
{ // if there are no DNS records
	// return array('isValid' => false, 'reason' => 'Invalid E-Mail DNS Entry! ('.$emailDomain.')');
	echo '<p>'.$emailDomain.' is invalid...</p>';
}
else
{
	// find the highest priority server
	$index = 0;
	$priority = $dnsr[0][pri];
	foreach ($dnsr as $i => $array)
	{
		if ($dnsr[$i][pri] < $priority)
		{
			$priority = $dnsr[$i][pri];
			$index = $i;
		}
	}

	$reply = array();
	$err = array ('no' => NULL, 'str' => "");
	if (!$socket = fsockopen($dnsr[$index]['target'], 25, $err['no'], $err['str'], 30))
	{
		// return array('isValid' => false, 'reason' => 'Connection Failed (Error No. '.$err['no'].': '.$err['str'].')');
		echo '<p>Connection Failed (Error No. '.$err['no'].': '.$err['str'].')</p>';
	}
	else
	{
		fwrite($socket, "HELO ".$_SERVER['HTTP_HOST']);
		while (!feof($socket))
		{
			$reply[] = fgets($socket,255);
		}
		fclose($socket);
	}
	print_r($reply);

}

 

and this is what it gives me:

Connection Failed (Error No. 111: Connection refused)

 

If I add 'udp://' to the fsocketopen command (fsockopen('udp://'.$dnsr[$index]['target'], 25, $err['no'], $err['str'], 30)) it stops giving me an error, but when I run it, the page will sit there and load forever and never actually return anything.

Link to comment
https://forums.phpfreaks.com/topic/191003-fsocketopen-and-e-mail-verrification/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.