You are here

public function PhpMailerSmtp::__construct in PHPMailer SMTP 2.0.x

Same name and namespace in other branches
  1. 8 src/Plugin/Mail/PhpMailerSmtp.php \Drupal\phpmailer_smtp\Plugin\Mail\PhpMailerSmtp::__construct()
  2. 2.x src/Plugin/Mail/PhpMailerSmtp.php \Drupal\phpmailer_smtp\Plugin\Mail\PhpMailerSmtp::__construct()
  3. 2.1.x src/Plugin/Mail/PhpMailerSmtp.php \Drupal\phpmailer_smtp\Plugin\Mail\PhpMailerSmtp::__construct()

Constructor.

File

src/Plugin/Mail/PhpMailerSmtp.php, line 129

Class

PhpMailerSmtp
Implements the base PHPMailer SMTP class for the Drupal MailInterface.

Namespace

Drupal\phpmailer_smtp\Plugin\Mail

Code

public function __construct(ConfigFactoryInterface $config, LoggerChannelFactoryInterface $logger_factory, MessengerInterface $messenger) {

  // Throw exceptions instead of dying (since 5.0.0).
  if (method_exists(get_parent_class($this), '__construct')) {
    parent::__construct(TRUE);
  }
  $this->configFactory = $config;
  $this->config = $config
    ->get('phpmailer_smtp.settings');
  $this->loggerFactory = $logger_factory;
  $this->messenger = $messenger;
  $this
    ->IsSMTP();
  $this
    ->Reset();
  $this->SMTPAutoTLS = FALSE;
  $this->Host = $this->config
    ->get('smtp_host', '');
  if ($backup = $this->config
    ->get('smtp_hostbackup', '')) {
    $this->Host .= ';' . $backup;
  }
  $this->Port = $this->config
    ->get('smtp_port', '25');
  $smtp_protocol = $this->config
    ->get('smtp_protocol', '');
  $this->SMTPSecure = $smtp_protocol;
  if (!empty($smtp_protocol)) {
    $ssl_verify_peer = $this->config
      ->get('smtp_ssl_verify_peer');
    $this->SMTPOptions['ssl']['verify_peer'] = isset($ssl_verify_peer) ? $ssl_verify_peer : 1;
    $ssl_verify_peer_name = $this->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 = $this->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 = $this->config
    ->get('smtp_username', '');
  $this->Password = $this->config
    ->get('smtp_password', '');
  $this->SMTPAuth = (bool) ($this->Username != '' && $this->Password != '');
  $this->SMTPKeepAlive = $this->config
    ->get('smtp_keepalive', 0);
  $this->Timeout = $this->config
    ->get('smtp_timeout', 30);
  $this->drupalDebug = $this->config
    ->get('smtp_debug', 0);
  if ($this->drupalDebug > $this->SMTPDebug && \Drupal::currentUser()
    ->hasPermission('administer phpmailer smtp settings')) {
    $this->SMTPDebug = $this->drupalDebug;
  }
}