You are here

email_verify.install in Email Verify 5

File

email_verify.install
View source
<?php

/**
 * Implementation of hook_enable().
 */
function email_verify_enable() {

  // Check that fsockopen() works on port 25.
  // See: http://drupal.org/node/147883
  // What follows is an adapted version of email_verify_check().
  // The documentation http://api.drupal.org/api/5/function/hook_install says:
  //   "Note that since this function is called from a full bootstrap, all functions
  //    (including those in modules enabled by the current page request) are available
  //    when this hook is called. Use cases could be displaying a user message, or
  //    calling a module function necessary for initial setup, etc."
  // However, this does not seem to be the case, so we can't reuse email_verify_check().
  $host = 'drupal.org';

  // What SMTP servers should we contact?
  $mxHosts = array();
  if (!getmxrr($host, $mxHosts)) {

    // When there is no MX record, the host itself should be used
    $mxHosts[] = $host;
  }

  // Try to connect to one SMTP server
  foreach ($mxHosts as $smtpServer) {
    $connect = @fsockopen($smtpServer, 25, $errno, $errstr, 15);
    if (!$connect) {
      continue;
    }
    if (ereg("^220", $out = fgets($connect, 1024))) {

      // OK, we have a SMTP connection
      break;
    }
  }
  if (!$connect) {
    $message = t('Email_verify.module has tried contacting the mail host @drupal.org, but didn\'t receive any reply.<br />
      Check with your hosting provider that the function fscokopen() is properly configured on your server,
      and that the port 25 is open.<br />
      <strong>The module email_verify has been disabled.</strong>');
    watchdog('email_verify', $message, WATCHDOG_ERROR);
    drupal_set_message($message, 'error');
    module_disable(array(
      'email_verify',
    ));
  }
}

Functions

Namesort descending Description
email_verify_enable Implementation of hook_enable().