You are here

phpmailer.install in PHPMailer 8.3

PHPMailer installation functions.

File

phpmailer.install
View source
<?php

/**
 * @file
 * PHPMailer installation functions.
 */

/**
 * Implementation of hook_requirements().
 */
function phpmailer_requirements($phase) {
  $requirements = [];
  if (class_exists('PHPMailer')) {
    $mail = new PHPMailer();
  }
  if (empty($mail)) {
    $requirements['phpmailer'] = [
      '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 = '5.2.26';
    $installed_version = $mail->Version;
    $requirements['phpmailer'] = [
      'title' => (string) t('PHPMailer library'),
      'value' => $installed_version,
    ];
    if (!version_compare($installed_version, $required_version, '>=')) {
      $requirements['phpmailer']['severity'] = REQUIREMENT_ERROR;
      $requirements['phpmailer']['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']['severity'] = REQUIREMENT_OK;
    }
  }
  return $requirements;
}

/**
 * Implementation of hook_install().
 */
function phpmailer_install() {

  /**
   *  @todo This part needs to be figured out.
   */

  //  if (!phpmailer_active() && !(\Drupal::moduleHandler()->moduleExists('mimemail') && variable_get('mimemail_engine', 'mimemail') == 'phpmailer')) {
  if (!phpmailer_active()) {
    drupal_set_message(t('PHPMailer has been installed, but it is not currently active. Activate and configure it by navigating to Configuration > System > PHPMailer (/admin/config/system/phpmailer).'));
  }

  //  if (\Drupal::moduleHandler()->moduleExists('mailsystem')) {
  //    /**
  //     *  @todo This part needs to be figured out.
  //     */
  //    mailsystem_set(['phpmailer' => 'DrupalPHPMailer']);
  //  }
}

/**
 * Implementation of hook_uninstall().
 */
function phpmailer_uninstall() {

  /**
   *  @todo This part needs to be figured out.
   */

  //  $mail_system = variable_get('mail_system', ['default-system' => 'DefaultMailSystem']);
  //  $mail_system['default-system'] = 'DefaultMailSystem';
  //  variable_set('mail_system', $mail_system);
  if (phpmailer_active()) {

    // Remove PHPMailer from all mail keys it is configured for.
    //    $mail_system = variable_get('mail_system', ['default-system' => 'DefaultMailSystem']);
    //    foreach ($mail_system as $key => $class) {
    //      if ($class == 'DrupalPHPMailer') {
    //        if ($key != 'default-system') {
    //          unset($mail_system[$key]);
    //        }
    //        else {
    //          $mail_system[$key] = 'DefaultMailSystem';
    //        }
    //      }
    //    }
    //    variable_set('mail_system', $mail_system);
    \Drupal::configFactory()
      ->getEditable('phpmailer.settings')
      ->clear('smtp_on')
      ->save();
    drupal_set_message(t('PHPMailer has been disabled.'));
  }

  /**
   *  @todo Need to find out where this variable comes from.
   */

  //  if (\Drupal::moduleHandler()->moduleExists('mimemail') && variable_get('mimemail_engine', 'mimemail') == 'phpmailer') {
  // This variable does not exist in the D8 port of Mime Mail.
  //    variable_del('mimemail_engine');
  //    drupal_set_message(t('MimeMail e-mail engine has been reset to default.'), 'warning');
  //  }
  if (\Drupal::moduleHandler()
    ->moduleExists('mailsystem')) {

    // This function does not exist in the D8 port of Mail System.
    //    mailsystem_clear(['phpmailer' => 'DrupalPHPMailer']);
  }
}

Functions

Namesort descending Description
phpmailer_install Implementation of hook_install().
phpmailer_requirements Implementation of hook_requirements().
phpmailer_uninstall Implementation of hook_uninstall().