diff --git a/email_verify.admin.inc b/email_verify.admin.inc
index 18d03e6..61e57f0 100644
--- a/email_verify.admin.inc
+++ b/email_verify.admin.inc
@@ -52,6 +52,53 @@ function email_verify_admin_settings($form, &$form_state) {
     '#description' => t('The connection timeout, in seconds. The default is "15".'),
   );
 
+  $form['email_verify_debug_mode'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Debug mode'),
+    '#collapsible' => TRUE,
+  );
+  $form['email_verify_debug_mode']['email_verify_debug_mode'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Enable'),
+    '#default_value' => variable_get('email_verify_debug_mode', FALSE),
+    '#description' => t('Check this box to get verbose information about each email address verification made.'),
+  );
+  $form['email_verify_debug_mode']['email_verify_debug_mode_record_log'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Record debugging information in the database log'),
+    '#default_value' => variable_get('email_verify_debug_mode_record_log', FALSE),
+    '#states' => array('enabled' => array(':input[name="email_verify_debug_mode"]' => array('checked' => TRUE))),
+  );
+  $form['email_verify_debug_mode']['email_verify_debug_mode_display_page'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Display debugging information on the page'),
+    '#default_value' => variable_get('email_verify_debug_mode_display_page', FALSE),
+    '#states' => array('enabled' => array(':input[name="email_verify_debug_mode"]' => array('checked' => TRUE))),
+  );
+  $date_types = system_get_date_types();
+  $options = array();
+  foreach ($date_types as $date_type) {
+    $options[$date_type['type']] = $date_type['title'];
+  }
+  $form['email_verify_debug_mode']['email_verify_debug_mode_date_format'] = array(
+    '#type' => 'select',
+    '#title' => t('Date/time format'),
+    '#default_value' => variable_get('email_verify_debug_mode_date_format', ''),
+    '#options' => $options,
+    '#description' => t('Select the date format to use when displaying the dates and times in the debug information.<br />
+      Date types and formats can be modified in the system !datetime settings pages.', array('!datetime' => l(t('Date and time'), 'admin/config/regional/date-time'))),
+    '#states' => array('enabled' => array(':input[name="email_verify_debug_mode"]' => array('checked' => TRUE))),
+  );
+
+//  $options = array('loose' => t('Loose (fail for some failures)'), 'medium' => t('Medium (fail for most common failures)'), 'strict' => t('Strict (fail for all failed checks)'));
+//  $form['email_verify_modes']['email_verify_verification_mode'] = array(
+//    '#type' => 'select',
+//    '#title' => t('Check for any DNS records'),
+//    '#options' => $options,
+//    '#default_value' => variable_get('email_verify_verification_mode', 1),
+//    '#description' => t("Use PHP's checkdnsrr() function to see if there are any DNS records associated with the email address' domain name."),
+//  );
+
   $form['email_verify_forms'] = array(
     '#type' => 'fieldset',
     '#title' => t('Forms to check'),
@@ -124,7 +171,17 @@ function email_verify_admin_settings_submit($form, &$form_state) {
   // Enable/disable mail sending subsystem.
   if ($form_state['values']['email_verify_active']) {
     if (!email_verify_activated()) {
-      email_verify_enable_module();
+      $debugging_text = email_verify_enable_module();
+      if (!empty($debugging_text)) {
+        // Log and/or display the debugging information.
+        $message = implode('<br />', $debugging_text);
+        if (variable_get('email_verify_debug_mode_record_log', FALSE)) {
+          watchdog('email_verify debug', $message, array(), WATCHDOG_DEBUG);
+        }
+        if (variable_get('email_verify_debug_mode_display_page', FALSE)) {
+          drupal_set_message($message);
+        }
+      }
     }
   }
 }
@@ -137,6 +194,16 @@ function email_verify_admin_settings_submit($form, &$form_state) {
  *   that it is not in email_verify.install.
  */
 function email_verify_enable_module() {
+  $debugging_mode = variable_get('email_verify_debug_mode', FALSE);
+  $date_time_format = variable_get('email_verify_debug_mode_date_format', 'long');
+  $debugging_text = array();
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Beginning the system capability checks for the Email Verify module (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
+
   // Check that fsockopen() works on port 25.
   // @see: http://drupal.org/node/147883
 
@@ -153,49 +220,232 @@ function email_verify_enable_module() {
   // If a previous enable found port 25 closed or fsockopen() disabled, don't
   // test it again. Testing can cause a long delay on module enable. Completely
   // uninstall and then re-install this module to re-test.
-  If (variable_get('email_verify_skip_mailbox', FALSE)) {
-    return;
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Checking to see if the system capability checks have already been run (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
+  if (variable_get('email_verify_skip_mailbox', FALSE)) {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'The system capability checks have already been run, so the system capability check is stopping (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
+    return $debugging_text;
+  }
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'The system capability checks have not been run, so the system capability check is continuing (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
   }
 
   // Check if fsockopen() is disabled.
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Checking to see if fsockopen() is enabled or disabled (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
   if (!function_exists('fsockopen')) {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'The fsockopen() function does not exist, so the system capability check is stopping (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
     $message = t('Email Verify will test email domains but not mailboxes because the fsockopen() function has been disabled.');
     variable_set('email_verify_skip_mailbox', TRUE);
     drupal_set_message($message, 'warning');
-    return;
+    return $debugging_text;
+  }
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'The fsockopen() function exists, so the system capability check is continuing (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
   }
 
   $host = variable_get('email_verify_test_options_host_name', 'drupal.org');
-  // What SMTP servers should we contact?
-  $mx_hosts = array();
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'The host that will be used for checking the system capability is "%host" (!date_time).',
+      array(
+        '%host' => $host,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
 
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Checking to see if Microsoft Windows compatible functions are needed (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
   if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'Microsoft Windows was detected, so the compatible functions are being loaded (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
     module_load_include('inc', 'email_verify', 'windows_compat');
   }
+  else {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'Microsoft Windows was not detected, so the compatible functions are not being loaded (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
+  }
 
+  // What SMTP servers should we contact?
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Retrieving any MX records corresponding to the specified host "%host" (!date_time).',
+      array(
+        '%host' => $host,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
+  $mx_hosts = array();
   if (!getmxrr($host, $mx_hosts)) {
     // When there is no MX record, the host itself should be used.
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'No MX records were found, so the host itself will be used to check the system capability (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
     $mx_hosts[] = $host;
   }
+  else {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'MX records were found, so they will be used to check the system capability (!date_time): !mx_hosts',
+        array(
+          '!date_time' => format_date(time(), $date_time_format),
+          '!mx_hosts' => '<pre>' . print_r($mx_hosts, TRUE) . '</pre>',
+        )
+      );
+    }
+  }
 
   $timeout = variable_get('email_verify_test_options_timeout', 15);
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'The timeout setting for checking the system capability is "%timeout" seconds (!date_time).',
+      array(
+        '%timeout' => $timeout,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
+
   // Try to connect to one SMTP server.
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Checking the host(s) to see if a connection can be made to any of them (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
   foreach ($mx_hosts as $smtp) {
     $connect = @fsockopen($smtp, 25, $errno, $errstr, $timeout);
+    if ($debugging_mode) {
+      if ($connect === FALSE) {
+        $debugging_text[] = t(
+          'The attempt to connect to host "%smtp" failed. If provided, the error number was "%errno", and the error string was "%errstr" (!date_time).',
+          array(
+            '%smtp' => $smtp,
+            '%errno' => $errno,
+            '%errstr' => $errstr,
+            '!date_time' => format_date(time(), $date_time_format),
+          )
+        );
+      }
+      else {
+        $debugging_text[] = t(
+          'The attempt to connect to host "%smtp" succeeded. If provided, the error number was "%errno", and the error string was "%errstr" (!date_time).',
+          array(
+            '%smtp' => $smtp,
+            '%errno' => $errno,
+            '%errstr' => $errstr,
+            '!date_time' => format_date(time(), $date_time_format),
+          )
+        );
+      }
+    }
     if (!$connect) {
+      if ($debugging_mode) {
+        $debugging_text[] = t(
+          'The system could not connect to "%smtp" and is continuing to the next host in the list (!date_time).',
+          array(
+            '%smtp' => $smtp,
+            '!date_time' => format_date(time(), $date_time_format),
+          )
+        );
+      }
+      if ($connect === FALSE && $errno === 0) {
+        if ($debugging_mode) {
+          $debugging_text[] = t(
+            'The result of fsockopen() was FALSE, and the error number was 0, which indicates a potential problem initializing the socket. This is the error string: "%errstr" (!date_time).',
+            array(
+              '%errstr' => $errstr,
+              '!date_time' => format_date(time(), $date_time_format),
+            )
+          );
+        }
+        watchdog('email_verify', 'There was a potential problem initializing the socket when attempting to check an email address.', array(), WATCHDOG_WARNING);
+      }
       continue;
     }
 
     if (preg_match("/^220/", $out = fgets($connect, 1024))) {
       // OK, we have a SMTP connection.
+      if ($debugging_mode) {
+        $debugging_text[] = t(
+          'A connection was made to "%smtp", and so the system capability check is continuing (!date_time).',
+          array(
+            '%smtp' => $smtp,
+            '!date_time' => format_date(time(), $date_time_format),
+          )
+        );
+      }
       break;
     }
   }
 
   if (!$connect) {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'No connection could be made to any host. Domains will be checked for validity, but mailboxes cannot be checked (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
     variable_set('email_verify_skip_mailbox', TRUE);
     $message = t('Email Verify will test email domains but not mailboxes because port 25 is closed on your host\'s firewall for security.');
     watchdog('email_verify', $message, array(), WATCHDOG_WARNING);
     drupal_set_message($message, 'warning');
   }
+  else {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'A connection was made to a host, so the system has passed the capability check (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
+  }
+
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Ending the system capability checks for the Email Verify module (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
+  return $debugging_text;
 }
diff --git a/email_verify.check.inc b/email_verify.check.inc
index 86debe2..da353da 100644
--- a/email_verify.check.inc
+++ b/email_verify.check.inc
@@ -201,16 +201,26 @@ function _email_verify_batch_display_process_batch($user_count, $offset, $disabl
     $account = user_load($user->uid);
     // Check the user account.
     $check_results = email_verify_check($account->mail);
-    if ($check_results) {
+    if (!empty($check_results['verification_message'])) {
       // Add the user to the list.
       $context['results']['users_to_display'][$account->uid] = array(
         'uid' => $account->uid,
         'name' => $account->name,
         'mail' => $account->mail,
-        'reason' => $check_results,
+        'reason' => $check_results['verification_message'],
         'link' => l('account', 'user/' . $account->uid),
       );
     }
+    if (!empty($check_results['debugging_text'])) {
+      // Log and/or display the debugging information.
+      $message = implode('<br />', $check_results['debugging_text']);
+      if (variable_get('email_verify_debug_mode_record_log', FALSE)) {
+        watchdog('email_verify debug', $message, array(), WATCHDOG_DEBUG);
+      }
+      if (variable_get('email_verify_debug_mode_display_page', FALSE)) {
+        drupal_set_message($message);
+      }
+    }
 
     // Update the progress information.
     $context['sandbox']['current_count']++;
diff --git a/email_verify.inc.php b/email_verify.inc.php
index 7acbb6f..dddda3c 100644
--- a/email_verify.inc.php
+++ b/email_verify.inc.php
@@ -8,80 +8,372 @@
  * Checks the email address for validity.
  */
 function _email_verify_check($mail) {
+  $debugging_mode = variable_get('email_verify_debug_mode', FALSE);
+  $date_time_format = variable_get('email_verify_debug_mode_date_format', 'long');
+  $debugging_text = array();
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Beginning the verification of email address "%mail" (!date_time).',
+      array(
+        '%mail' => $mail,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
+
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Checking if the address is syntactically incorrect (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
   if (!valid_email_address($mail)) {
     // The address is syntactically incorrect. The problem will be caught by the
     // user module, so avoid duplicating the error reporting by just returning.
-    return;
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'The address is not syntactically correct, so verification is stopping here (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
+    return array(
+      'verification_message' => '',
+      'debugging_text' => $debugging_text,
+    );
+  }
+  else {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'The address is syntactically correct, so verification is continuing (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
   }
 
   // If this is a Windows based computer, load the Windows compatibilty file.
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Checking to see if Microsoft Windows compatible functions are needed (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
   if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'Microsoft Windows was detected, so the compatible functions are being loaded (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
     module_load_include('inc', 'email_verify', 'windows_compat');
   }
+  else {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'Microsoft Windows was not detected, so the compatible functions are not being loaded (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
+  }
 
   $host = drupal_substr(strchr($mail, '@'), 1);
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'The host that will be used for verifying the email address is "%host" (!date_time).',
+      array(
+        '%host' => $host,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
+
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Checking to see if a dot should be added to the domain name (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
   if (variable_get('email_verify_methods_add_dot', 1)) {
     $host = $host . '.';
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'Adding a dot to the domain name. The new host to use for verification is "%host" (!date_time).',
+        array(
+          '%host' => $host,
+          '!date_time' => format_date(time(), $date_time_format),
+        )
+      );
+    }
+  }
+  else {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'Not adding a dot to the domain name (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
   }
 
   // Check the DNS records of the email address' domain name to see if anything
   // is reported.
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Checking to see if the checkdnsrr() method should be used to verify the domain name (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
   if (variable_get('email_verify_methods_checkdnsrr', 1)) {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'The checkdnsrr() method will be used to verify the domain name (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
     if (!checkdnsrr($host, 'ANY')) {
-      watchdog('email_verify', "No DNS records were found, using checkdnsrr() with '%host' for host and 'ANY' for type.", array('%host' => $host));
+      if ($debugging_mode) {
+        $debugging_text[] = t(
+          'No DNS records were found for host "%host", so verification is stopping here (!date_time).',
+          array(
+            '%host' => $host,
+            '!date_time' => format_date(time(), $date_time_format),
+          )
+        );
+      }
+      watchdog('email_verify', 'No DNS records were found, using checkdnsrr() with "%host" for host and "ANY" for type.', array('%host' => $host));
       if (function_exists('email_verify_access_people_email_verify') && email_verify_access_people_email_verify()) {
-        return t("No DNS records were found, using checkdnsrr() with '%host' for host and 'ANY' for type.", array('%host' => $host));
+        return array(
+          'verification_message' => t('No DNS records were found, using checkdnsrr() with "%host" for host and "ANY" for type.', array('%host' => $host)),
+          'debugging_text' => $debugging_text,
+        );
       }
       else {
-        return t('%host is not a valid email host. Please check the spelling and try again.', array('%host' => "$host"));
+        return array(
+          'verification_message' => t('%host is not a valid email host. Please check the spelling and try again.', array('%host' => "$host")),
+          'debugging_text' => $debugging_text,
+        );
+      }
+    }
+    else {
+      if ($debugging_mode) {
+        $debugging_text[] = t(
+          'DNS records were found for host "%host", so verification is continuing (!date_time).',
+          array(
+            '%host' => $host,
+            '!date_time' => format_date(time(), $date_time_format),
+          )
+        );
       }
     }
   }
+  else {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'The checkdnsrr() method will not be used to verify the domain name (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
+  }
 
   // Check to see if the email address' domain name resolves to an IPv4 address.
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Checking to see if the gethostbyname() method should be used to verify the domain name (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
   if (variable_get('email_verify_methods_gethostbyname', 1)) {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'The gethostbyname() method will be used to verify the domain name (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
     if (gethostbyname($host) == $host) {
+      if ($debugging_mode) {
+        $debugging_text[] = t(
+          'No IPv4 address was found for host "%host", so verification is stopping here (!date_time).',
+          array(
+            '%host' => $host,
+            '!date_time' => format_date(time(), $date_time_format),
+          )
+        );
+      }
       watchdog('email_verify', 'No IPv4 address was found, using gethostbyname() with %host.', array('%host' => $host));
       if (function_exists('email_verify_access_people_email_verify') && email_verify_access_people_email_verify()) {
-        return t('No IPv4 address was found, using gethostbyname() with %host.', array('%host' => $host));
+        return array(
+          'verification_message' => t('No IPv4 address was found, using gethostbyname() with %host.', array('%host' => $host)),
+          'debugging_text' => $debugging_text,
+        );
       }
       else {
-        return t('%host is not a valid email host. Please check the spelling and try again.', array('%host' => "$host"));
+        return array(
+          'verification_message' => t('%host is not a valid email host. Please check the spelling and try again.', array('%host' => "$host")),
+          'debugging_text' => $debugging_text,
+        );
       }
     }
+    else {
+      if ($debugging_mode) {
+        $debugging_text[] = t(
+          'IPv4 address was found for host "%host", so verification is continuing (!date_time).',
+          array(
+            '%host' => $host,
+            '!date_time' => format_date(time(), $date_time_format),
+          )
+        );
+      }
+    }
+  }
+  else {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'The gethostbyname() method will not be used to verify the domain name (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
   }
 
   // If install found port 25 closed or fsockopen() disabled, we can't test
   // mailboxes.
-  If (variable_get('email_verify_skip_mailbox', FALSE)) {
-    return;
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Checking to see if the "email_verify_skip_mailbox" variable is set to TRUE, indicating that the system is unable to check mailboxes (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
+  if (variable_get('email_verify_skip_mailbox', FALSE)) {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'The "email_verify_skip_mailbox" variable is set to TRUE, so verification is stopping here (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
+    return array(
+      'verification_message' => '',
+      'debugging_text' => $debugging_text,
+    );
+  }
+  else {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'The "email_verify_skip_mailbox" variable is set to FALSE, so verification is continuing (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
   }
 
   // What SMTP servers should we contact?
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Retrieving any MX records corresponding to the specified host "%host" (!date_time).',
+      array(
+        '%host' => $host,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
   $mx_hosts = array();
   if (!getmxrr($host, $mx_hosts)) {
     // When there is no MX record, the host itself should be used.
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'No MX records were found, so the host itself will be used to check the system capability (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
     $mx_hosts[] = $host;
   }
+  else {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'MX records were found, so they will be used to check the system capability (!date_time): !mx_hosts',
+        array(
+          '!date_time' => format_date(time(), $date_time_format),
+          '!mx_hosts' => '<pre>' . print_r($mx_hosts, TRUE) . '</pre>',
+        )
+      );
+    }
+  }
+
+  $timeout = variable_get('email_verify_test_options_timeout', 15);
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'The timeout setting for checking the system capability is "%timeout" seconds (!date_time).',
+      array(
+        '%timeout' => $timeout,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
 
   // Try to connect to one SMTP server.
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Checking the host(s) to see if a connection can be made to any of them (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
   foreach ($mx_hosts as $smtp) {
-    /**
-     * @todo
-     *   This needs to be examined and possibly corrected.
-     */
-    $connect = @fsockopen($smtp, 25, $errno, $errstr, 15);
-
+    $connect = @fsockopen($smtp, 25, $errno, $errstr, $timeout);
+    if ($debugging_mode) {
+      if ($connect === FALSE) {
+        $debugging_text[] = t(
+          'The attempt to connect to host "%smtp" failed. If provided, the error number was "%errno", and the error string was "%errstr" (!date_time).',
+          array(
+            '%smtp' => $smtp,
+            '%errno' => $errno,
+            '%errstr' => $errstr,
+            '!date_time' => format_date(time(), $date_time_format),
+          )
+        );
+      }
+      else {
+        $debugging_text[] = t(
+          'The attempt to connect to host "%smtp" succeeded. If provided, the error number was "%errno", and the error string was "%errstr" (!date_time).',
+          array(
+            '%smtp' => $smtp,
+            '%errno' => $errno,
+            '%errstr' => $errstr,
+            '!date_time' => format_date(time(), $date_time_format),
+          )
+        );
+      }
+    }
     if (!$connect) {
+      if ($debugging_mode) {
+        $debugging_text[] = t(
+          'The system could not connect to "%smtp" and is continuing to the next host in the list (!date_time).',
+          array(
+            '%smtp' => $smtp,
+            '!date_time' => format_date(time(), $date_time_format),
+          )
+        );
+      }
       if ($connect === FALSE && $errno === 0) {
+        if ($debugging_mode) {
+          $debugging_text[] = t(
+            'The result of fsockopen() was FALSE, and the error number was 0, which indicates a potential problem initializing initializing the socket. This is the error string: "%errstr" (!date_time).',
+            array(
+              '%errstr' => $errstr,
+              '!date_time' => format_date(time(), $date_time_format),
+            )
+          );
+        }
         watchdog('email_verify', 'There was a potential problem initializing the socket when attempting to check an email address.', array(), WATCHDOG_WARNING);
       }
-
       continue;
     }
 
-    if (preg_match("/^220/", $out = fgets($connect, 1024))) {
+    if (preg_match("/^220/", $connect_result = fgets($connect, 1024))) {
       // An SMTP connection was made.
+      if ($debugging_mode) {
+        $debugging_text[] = t(
+          'A connection was made to "%smtp", and so verification will stop connecting to hosts and continue (!date_time).',
+          array(
+            '%smtp' => $smtp,
+            '!date_time' => format_date(time(), $date_time_format),
+          )
+        );
+      }
       break;
     }
     else {
@@ -89,81 +381,276 @@ function _email_verify_check($mail) {
       // aol.com for instance).
       // Be on the safe side and accept the address, at least it has a valid
       // domain part.
-      watchdog('email_verify', 'Could not verify email address at host @host: @out', array('@host' => $host, '@out' => $out), WATCHDOG_WARNING);
+      if ($debugging_mode) {
+        $debugging_text[] = t(
+          'A connection was made to "%smtp", but a positive response was not recieved. Verification is stopping here (!date_time).',
+          array(
+            '%smtp' => $smtp,
+            '!date_time' => format_date(time(), $date_time_format),
+          )
+        );
+      }
+      watchdog('email_verify', 'Could not verify email address at host %host: %connect_result', array('%host' => $host, '%connect_result' => $connect_result), WATCHDOG_WARNING);
       if (function_exists('email_verify_access_people_email_verify') && email_verify_access_people_email_verify()) {
-        return t('Could not verify email address at host @host: @out', array('@host' => $host, '@out' => $out));
+        return array(
+          'verification_message' => t('Could not verify email address at host %host: %connect_result', array('%host' => $host, '%connect_result' => $connect_result)),
+          'debugging_text' => $debugging_text,
+        );
       }
       else {
-        return;
+        return array(
+          'verification_message' => '',
+          'debugging_text' => $debugging_text,
+        );
       }
     }
   }
 
   if (!$connect) {
-    return t('%host is not a valid email host. Please check the spelling and try again or contact us for clarification.', array('%host' => "$host"));
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'No connection could be made to any host, so verification is stopping here (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
+    return array(
+      'verification_message' => t('%host is not a valid email host. Please check the spelling and try again or contact us for clarification.', array('%host' => "$host")),
+      'debugging_text' => $debugging_text,
+    );
   }
 
-  $from = variable_get('site_mail', ini_get('sendmail_from'));
+  $from_address = variable_get('site_mail', ini_get('sendmail_from'));
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'The email address to use as the From address for the verification tests is "%from_address" (!date_time).',
+      array(
+        '%from_address' => $from_address,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
 
   // Extract the <...> part, if there is one.
-  if (preg_match('/\<(.*)\>/', $from, $match) > 0) {
-    $from = $match[1];
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Checking to see if From address needs to have non-email address text removed (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
+  if (preg_match('/\<(.*)\>/', $from_address, $match) > 0) {
+    $from_address = $match[1];
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'The From address needed to have non-email address text removed. The new From address to use for verification is "%from_address" (!date_time).',
+        array(
+          '%from_address' => $from_address,
+          '!date_time' => format_date(time(), $date_time_format),
+        )
+      );
+    }
+  }
+  else {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'The From address did not need to have non-email address text removed (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
   }
 
   // Should be good enough for RFC compliant SMTP servers.
   $localhost = $_SERVER["HTTP_HOST"];
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'The domain to use as the From host for the verification tests is "%localhost" (!date_time).',
+      array(
+        '%localhost' => $localhost,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
   if (!$localhost) {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'The domain to use as the From host was empty, "localhost" wil be used instead (!date_time).',
+        array('!date_time' => format_date(time(), $date_time_format))
+      );
+    }
     $localhost = 'localhost';
   }
 
   // Conduct the test.
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Connecting to the host with the command "HELO %localhost" (!date_time).',
+      array(
+        '%localhost' => $localhost,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
   fputs($connect, "HELO $localhost\r\n");
-  $out = fgets($connect, 1024);
-  fputs($connect, "MAIL FROM: <$from>\r\n");
-  $from = fgets($connect, 1024);
+  $connect_result = fgets($connect, 1024);
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'The first 1024 charcters of the response to the HELO command: "%connect_result" (!date_time).',
+      array(
+        '%connect_result' => $connect_result,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Connecting to the host with the command "MAIL FROM: %from_address" (!date_time).',
+      array(
+        '%from_address' => $from_address,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
+  fputs($connect, "MAIL FROM: <$from_address>\r\n");
+  $from_result = fgets($connect, 1024);
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'The first 1024 charcters of the response to the MAIL FROM command: "%from_result" (!date_time).',
+      array(
+        '%from_result' => $from_result,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Connecting to the host with the command "RCPT TO: {%mail}" (!date_time).',
+      array(
+        '%mail' => $mail,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
   fputs($connect, "RCPT TO: <{$mail}>\r\n");
-  $to = fgets($connect, 1024);
+  $to_result = fgets($connect, 1024);
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'The first 1024 charcters of the response to the RCPT TO command: "%to_result" (!date_time).',
+      array(
+        '%to_result' => $to_result,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Connecting to the host with the command "QUIT" (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
   fputs($connect, "QUIT\r\n");
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Closing the connection to the host (!date_time).',
+      array('!date_time' => format_date(time(), $date_time_format))
+    );
+  }
   fclose($connect);
 
   // Check the results.
-  if (!preg_match("/^250/", $from)) {
+  if (!preg_match("/^250/", $from_result)) {
     // Again, something went wrong before we could really test the address.
     // Be on the safe side and accept it.
-    watchdog('email_verify', 'Could not verify email address at host @host: @from', array('@host' => $host, '@from' => $from), WATCHDOG_WARNING);
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'A positive response was not recieved from the mail server. The result was "%from_result". Verification is stopping here (!date_time).',
+        array(
+          '%from_result' => $from_result,
+          '!date_time' => format_date(time(), $date_time_format),
+        )
+      );
+    }
+    watchdog('email_verify', 'Could not verify email address at host %host: %from_result', array('%host' => $host, '%from_result' => $from_result), WATCHDOG_WARNING);
     if (function_exists('email_verify_access_people_email_verify') && email_verify_access_people_email_verify()) {
-      return t('Could not verify email address at host @host: @from', array('@host' => $host, '@from' => $from));
+      return array(
+        'verification_message' => t('Could not verify email address at host %host: %from_result', array('%host' => $host, '%from_result' => $from_result)),
+        'debugging_text' => $debugging_text,
+      );
     }
     else {
-      return;
+      return array(
+        'verification_message' => '',
+        'debugging_text' => $debugging_text,
+      );
     }
   }
   if (
       // This server does not like us (noos.fr behaves like this for instance).
-      preg_match("/(Client host|Helo command) rejected/", $to) ||
+      preg_match("/(Client host|Helo command) rejected/", $to_result) ||
       // Any 4xx error also means we couldn't really check except 450, which is
       // explcitely a non-existing mailbox: 450 = "Requested mail action not
       // taken: mailbox unavailable".
-      preg_match("/^4/", $to) && !preg_match("/^450/", $to)) {
+      preg_match("/^4/", $to_result) && !preg_match("/^450/", $to_result)) {
     // In those cases, accept the email, but log a warning.
-    watchdog('email_verify', 'Could not verify email address at host @host: @to', array('@host' => $host, '@to' => $to), WATCHDOG_WARNING);
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'A positive response was not recieved from the mail server. The result was "%to_result". Verification is stopping here (!date_time).',
+        array(
+          '%to_result' => $to_result,
+          '!date_time' => format_date(time(), $date_time_format),
+        )
+      );
+    }
+    watchdog('email_verify', 'Could not verify email address at host %host: %to_result', array('%host' => $host, '%to_result' => $to_result), WATCHDOG_WARNING);
     if (function_exists('email_verify_access_people_email_verify') && email_verify_access_people_email_verify()) {
-      return t('Could not verify email address at host @host: @to', array('@host' => $host, '@to' => $to));
+      return array(
+        'verification_message' => t('Could not verify email address at host %host: %to_result', array('%host' => $host, '%to_result' => $to_result)),
+        'debugging_text' => $debugging_text,
+      );
     }
     else {
-      return;
+      return array(
+        'verification_message' => '',
+        'debugging_text' => $debugging_text,
+      );
     }
   }
-  if (!preg_match("/^250/", $to)) {
-    watchdog('email_verify', 'Rejected email address: @mail. Reason: @to', array('@mail' => $mail, '@to' => $to), WATCHDOG_WARNING);
+  if (!preg_match("/^250/", $to_result)) {
+    if ($debugging_mode) {
+      $debugging_text[] = t(
+        'The To "%mail" address was rejected from the mail server. The result was "%to_result". Verification is stopping here (!date_time).',
+        array(
+          '%mail' => $mail,
+          '%to_result' => $to_result,
+          '!date_time' => format_date(time(), $date_time_format),
+        )
+      );
+    }
+    watchdog('email_verify', 'Rejected email address: %mail. Reason: %to_result', array('%mail' => $mail, '%to_result' => $to_result), WATCHDOG_WARNING);
     if (function_exists('email_verify_access_people_email_verify') && email_verify_access_people_email_verify()) {
-      return t('Rejected email address: @mail. Reason: @to', array('@mail' => $mail, '@to' => $to));
+      return array(
+        'verification_message' => t('Rejected email address: %mail. Reason: %to_result', array('%mail' => $mail, '%to_result' => $to_result)),
+        'debugging_text' => $debugging_text,
+      );
     }
     else {
-      return t('%mail is not a valid email address. Please check the spelling and try again or contact us for clarification.', array('%mail' => "$mail"));
+      return array(
+        'verification_message' => t('%mail is not a valid email address. Please check the spelling and try again or contact us for clarification.', array('%mail' => "$mail")),
+        'debugging_text' => $debugging_text,
+      );
     }
   }
 
   // Everything is OK, so don't return anything.
-  return;
+  if ($debugging_mode) {
+    $debugging_text[] = t(
+      'Ending the verification of email address "%mail". It has passed verification (!date_time).',
+      array(
+        '%mail' => $mail,
+        '!date_time' => format_date(time(), $date_time_format),
+      )
+    );
+  }
+  return array(
+    'verification_message' => '',
+    'debugging_text' => $debugging_text,
+  );
 }
diff --git a/email_verify.module b/email_verify.module
index ef8f6ea..0387e74 100644
--- a/email_verify.module
+++ b/email_verify.module
@@ -126,8 +126,20 @@ function email_verify_form_registration_form_alter(&$form, &$form_state, $form_i
 function email_verify_edit_validate($form, &$form_state) {
   if (!user_access('bypass email verification') && $form_state['values']['op'] != t('Cancel account')) {
     // Validate the e-mail address.
-    if ($error = email_verify_check($form_state['input']['mail'])) {
-      form_set_error('mail', $error);
+    $results = email_verify_check($form_state['input']['mail']);
+    if (!empty($results['debugging_text'])) {
+      // Log and/or display the debugging information.
+      $message = implode('<br />', $results['debugging_text']);
+      if (variable_get('email_verify_debug_mode_record_log', FALSE)) {
+        watchdog('email_verify debug', $message, array(), WATCHDOG_DEBUG);
+      }
+      if (variable_get('email_verify_debug_mode_display_page', FALSE)) {
+        drupal_set_message($message);
+      }
+    }
+    // Report the error and flag the form field.
+    if (!empty($results['verification_message'])) {
+      form_set_error('mail', $results['verification_message']);
     }
   }
 }
