You are here

function phpmailer_requirements in PHPMailer 7.4

Same name and namespace in other branches
  1. 8.3 phpmailer.install \phpmailer_requirements()
  2. 5.2 phpmailer.install \phpmailer_requirements()
  3. 6.3 phpmailer.install \phpmailer_requirements()
  4. 6.2 phpmailer.install \phpmailer_requirements()
  5. 7.3 phpmailer.install \phpmailer_requirements()

Implements hook_requirements().

1 call to phpmailer_requirements()
phpmailer_settings_form in ./phpmailer.admin.inc
Form builder for both the Mime Mail settings and our own settings page.

File

./phpmailer.install, line 11
PHPMailer installation functions.

Code

function phpmailer_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break at install time.
  $t = get_t();
  if ($phase == 'runtime' && phpmailer_library_exists()) {
    $mail = new PHPMailer();
    $required_version = '5.2.21';
    $installed_version = $mail->Version;
    $requirements['phpmailer'] = array(
      'title' => $t('PHPMailer library'),
      'value' => $installed_version,
    );
    if (!version_compare($installed_version, $required_version, '>=')) {
      $path = 'sites/all/libraries/phpmailer';
      $requirements['phpmailer']['severity'] = REQUIREMENT_ERROR;
      $requirements['phpmailer']['description'] = $t('PHPMailer @version or higher is required. Please <a href="@url">download the new version</a>, extract the archive and copy the contents to the following location:<br /><code>@path</code>. Make sure the main file, class.phpmailer.php, is located at<br /><code>@class</code>.', array(
        '@version' => $required_version,
        '@url' => 'https://github.com/PHPMailer/PHPMailer/tags',
        '@path' => $path,
        '@class' => $path . '/class.phpmailer.php',
      ));
    }
    else {
      $requirements['phpmailer']['severity'] = REQUIREMENT_OK;
    }
  }
  else {
    drupal_load('module', 'libraries');
    $path = libraries_get_path('phpmailer');
    if (!$path || !file_exists(DRUPAL_ROOT . '/' . $path . '/class.phpmailer.php') || !file_exists(DRUPAL_ROOT . '/' . $path . '/class.smtp.php')) {

      // Since Libraries 2.x, $path is FALSE if the library does not exist.
      $path = 'sites/all/libraries/phpmailer';
      $requirements['phpmailer'] = array(
        'title' => $t('PHPMailer library'),
        'value' => $t('Missing'),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('Please download <a href="@url">PHPMailer for PHP5/6</a>, extract the archive and copy the contents to the following location:<br /><code>@path</code>. Make sure the main file, class.phpmailer.php, is located at<br /><code>@class</code>.', array(
          '@url' => 'https://github.com/PHPMailer/PHPMailer/tags',
          '@path' => $path,
          '@class' => $path . '/class.phpmailer.php',
        )),
      );
    }
  }
  return $requirements;
}