You are here

public function EmailVerifyManager::checkHost in Email Verify 8.2

File

src/EmailVerifyManager.php, line 145
Contains \Drupal\email_verify\EmailVerifyManager.

Class

EmailVerifyManager
Defines an email verify manager.

Namespace

Drupal\email_verify

Code

public function checkHost($host) {
  $config = $this->configFactory
    ->get('email_verify.settings');
  if ($config
    ->get('add_dot')) {
    $host = $host . '.';
  }
  if ($config
    ->get('checkdnsrr')) {
    if (!checkdnsrr($host, 'ANY')) {
      $this
        ->setError(t('@host is not a valid email host. Please check the spelling and try again.', array(
        '@host' => "{$host}",
      )));
    }
  }
  if ($config
    ->get('gethostbyname')) {
    if (gethostbyname($host) == $host) {
      \Drupal::logger('email_verify')
        ->warning('No IPv4 address was found using gethostbyname with @host', array(
        '@host' => $host,
      ));
      $this
        ->setError(t('@host is not a valid email host. Please check the spelling and try again or contact us for clarification.', array(
        '@host' => $host,
      )));
    }
  }
  if (!$this
    ->connect($host)) {
    $this
      ->setError(t('@host is not a valid email host. Please check the spelling and try again or contact us for clarification.', array(
      '@host' => $host,
    )));
  }
}