private function EmailVerifyManager::connect in Email Verify 8.2
2 calls to EmailVerifyManager::connect()
File
- src/
EmailVerifyManager.php, line 176 - Contains \Drupal\email_verify\EmailVerifyManager.
Class
- EmailVerifyManager
- Defines an email verify manager.
Namespace
Drupal\email_verifyCode
private function connect($host) {
if ($this->connection) {
return true;
}
// Find the MX records for the host. When there are no MX records, the host
// itself should be used.
$mx_hosts = array();
if (!getmxrr($host, $mx_hosts)) {
$mx_hosts[] = $host;
}
$config = $this->configFactory
->get('email_verify.settings');
$timeout = $config
->get('timeout');
// Try to connect to each MX host using SMTP port 25 in turn.
foreach ($mx_hosts as $smtp) {
$this->connection = @fsockopen($smtp, 25, $errno, $errstr, $timeout);
// Try each MX host sequentially if there is no response.
if (!$this->connection) {
continue;
}
// Successful SMTP connections break out of the loop.
if (preg_match("/^220/", $out = fgets($this->connection, 1024))) {
return true;
}
else {
// The SMTP server is probably a dynamic or residential IP. Since a
// valid domain has been used, accept the address.
\Drupal::logger('email_verify')
->warning('Could not verify email address at host @host: @out', array(
'@host' => $host,
'@out' => $out,
));
}
}
}