You are here

function phpmailer_smtp_requirements in PHPMailer SMTP 2.x

Same name and namespace in other branches
  1. 8 phpmailer_smtp.install \phpmailer_smtp_requirements()
  2. 2.0.x phpmailer_smtp.install \phpmailer_smtp_requirements()
  3. 2.1.x phpmailer_smtp.install \phpmailer_smtp_requirements()

Implements hook_requirements().

File

./phpmailer_smtp.install, line 13
PHPMailer SMTP installation functions.

Code

function phpmailer_smtp_requirements($phase) {
  $requirements = [];
  if (class_exists('PHPMailer\\PHPMailer\\PHPMailer')) {
    $mail = new PHPMailer();
  }
  if (empty($mail)) {
    $requirements['phpmailer_smtp'] = [
      'title' => (string) t('PHPMailer library'),
      'value' => (string) t('Missing'),
      'severity' => REQUIREMENT_ERROR,
      'description' => (string) t("Please install the PHPMailer library by executing 'composer update' in your site's root directory."),
    ];
  }
  else {
    $required_version = '6.1.7';
    $installed_version = $mail::VERSION;
    $requirements['phpmailer_smtp'] = [
      'title' => (string) t('PHPMailer library'),
      'value' => $installed_version,
    ];
    if (!version_compare($installed_version, $required_version, '>=')) {
      $requirements['phpmailer_smtp']['severity'] = REQUIREMENT_ERROR;
      $requirements['phpmailer_smtp']['description'] = (string) t("PHPMailer library @version or higher is required. Please install a newer version by executing 'composer update' in your site's root directory.", [
        '@version' => $required_version,
      ]);
    }
    else {
      $requirements['phpmailer_smtp']['severity'] = REQUIREMENT_OK;
    }
  }
  return $requirements;
}