You are here

public function DrupalPHPMailer::__construct in PHPMailer 8.3

Constructor.

File

src/Plugin/Mail/DrupalPHPMailer.php, line 62

Class

DrupalPHPMailer
Implements the base PHPMailer class for the Drupal MailInterface.

Namespace

Drupal\phpmailer\Plugin\Mail

Code

public function __construct() {

  // Throw exceptions instead of dying (since 5.0.0).
  if (method_exists(get_parent_class($this), '__construct')) {
    parent::__construct(TRUE);
  }
  $module_config = \Drupal::config('phpmailer.settings');
  $this
    ->IsSMTP();
  $this
    ->Reset();
  $this->Host = $module_config
    ->get('smtp_host', '');
  if ($backup = $module_config
    ->get('smtp_hostbackup', '')) {
    $this->Host .= ';' . $backup;
  }
  $this->Port = $module_config
    ->get('smtp_port', '25');
  $smtp_protocol = $module_config
    ->get('smtp_protocol', '');
  $this->SMTPSecure = $smtp_protocol;
  if (!empty($smtp_protocol)) {
    $ssl_verify_peer = $module_config
      ->get('smtp_ssl_verify_peer');
    $this->SMTPOptions['ssl']['verify_peer'] = isset($ssl_verify_peer) ? $ssl_verify_peer : 1;
    $ssl_verify_peer_name = $module_config
      ->get('smtp_ssl_verify_peer_name');
    $this->SMTPOptions['ssl']['verify_peer_name'] = isset($ssl_verify_peer_name) ? $ssl_verify_peer_name : 1;
    $ssl_allow_self_signed = $module_config
      ->get('smtp_ssl_allow_self_signed');
    $this->SMTPOptions['ssl']['allow_self_signed'] = isset($ssl_allow_self_signed) ? $ssl_allow_self_signed : 0;
  }

  // Use SMTP authentication if both username and password are given.
  $this->Username = $module_config
    ->get('smtp_username', '');
  $this->Password = $module_config
    ->get('smtp_password', '');
  $this->SMTPAuth = (bool) ($this->Username != '' && $this->Password != '');
  $this->SMTPKeepAlive = $module_config
    ->get('smtp_keepalive', 0);
  $this->Timeout = 30;
  $this->drupalDebug = $module_config
    ->get('smtp_debug', 0);
  if ($this->drupalDebug > $this->SMTPDebug && \Drupal::currentUser()
    ->hasPermission('administer phpmailer settings')) {
    $this->SMTPDebug = $this->drupalDebug;
  }
}