Errant_Shadow Posted February 5, 2010 Share Posted February 5, 2010 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 More sharing options...
Errant_Shadow Posted February 5, 2010 Author Share Posted February 5, 2010 I still can't figure out how this works and I can't seem to find anything online where it's being used the way I'm using it in any way that I can decompose and assimilate Link to comment https://forums.phpfreaks.com/topic/191003-fsocketopen-and-e-mail-verrification/#findComment-1007665 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.