We are trying to validate the email on our website and skip filling in the fake email on the quote form by the end user. we are using stream_socket_client() to check the "tcp://mx00.mail.com:25" It's working fine on our localhost Xampp Server but when we are deploying it to the live server it gets stuck and returns the timeout.
public function check($email) {
$result = FALSE;
if (!self::validate($email)) {
$this->set_error("{$email} incorrect e-mail");
$this->edebug($this->ErrorInfo);
if ($this->exceptions) {
throw new verifyEmailException($this->ErrorInfo);
}
return FALSE;
}
$this->error_count = 0; // Reset errors
$this->stream = FALSE;
$mxs = $this->getMXrecords(self::parse_email($email));
$timeout = ceil($this->max_connection_timeout / count($mxs));
foreach ($mxs as $host) {
/**
* suppress error output from stream socket client...
* Thanks Michael.
*/
$this->stream = @stream_socket_client("tcp://" . $host . ":" . $this->port, $errno, $errstr, $timeout);
if ($this->stream === FALSE) {
if ($errno == 0) {
$this->set_error("Problem initializing the socket");
$this->edebug($this->ErrorInfo);
if ($this->exceptions) {
throw new verifyEmailException($this->ErrorInfo);
}
return FALSE;
} else {
$this->edebug($host . ":" . $errstr);
}
} else {
stream_set_timeout($this->stream, $this->stream_timeout);
stream_set_blocking($this->stream, 1);
if ($this->_streamCode($this->_streamResponse()) == '220') {
$this->edebug("Connection success {$host}");
break;
} else {
fclose($this->stream);
$this->stream = FALSE;
}
}
}
if ($this->stream === FALSE) {
$this->set_error("All connection fails");
$this->edebug($this->ErrorInfo);
if ($this->exceptions) {
throw new verifyEmailException($this->ErrorInfo);
}
return FALSE;
}
$this->_streamQuery("HELO " . self::parse_email($this->from));
$this->_streamResponse();
$this->_streamQuery("MAIL FROM: <{$this->from}>");
$this->_streamResponse();
$this->_streamQuery("RCPT TO: <{$email}>");
$code = $this->_streamCode($this->_streamResponse());
$this->_streamResponse();
$this->_streamQuery("RSET");
$this->_streamResponse();
$code2 = $this->_streamCode($this->_streamResponse());
$this->_streamQuery("QUIT");
fclose($this->stream);
$code = !empty($code2)?$code2:$code;
switch ($code) {
case '250':
/**
* http://www.ietf.org/rfc/rfc0821.txt
* 250 Requested mail action okay, completed
* email address was accepted
*/
case '450':
case '451':
case '452':
/**
* http://www.ietf.org/rfc/rfc0821.txt
* 450 Requested action not taken: the remote mail server
* does not want to accept mail from your server for
* some reason (IP address, blacklisting, etc..)
* Thanks Nicht Lieb.
* 451 Requested action aborted: local error in processing
* 452 Requested action not taken: insufficient system storage
* email address was greylisted (or some temporary error occured on the MTA)
* i believe that e-mail exists
*/
return TRUE;
case '550':
return FALSE;
default :
return FALSE;
}
}
For Reference: Click Here