public function PhpMailerSmtp::__construct in PHPMailer SMTP 2.1.x
Same name and namespace in other branches
- 8 src/Plugin/Mail/PhpMailerSmtp.php \Drupal\phpmailer_smtp\Plugin\Mail\PhpMailerSmtp::__construct()
- 2.x src/Plugin/Mail/PhpMailerSmtp.php \Drupal\phpmailer_smtp\Plugin\Mail\PhpMailerSmtp::__construct()
- 2.0.x src/Plugin/Mail/PhpMailerSmtp.php \Drupal\phpmailer_smtp\Plugin\Mail\PhpMailerSmtp::__construct()
Constructor.
File
- src/
Plugin/ Mail/ PhpMailerSmtp.php, line 139
Class
- PhpMailerSmtp
- Implements the base PHPMailer SMTP class for the Drupal MailInterface.
Namespace
Drupal\phpmailer_smtp\Plugin\MailCode
public function __construct(ConfigFactoryInterface $config, LoggerChannelFactoryInterface $logger_factory, MessengerInterface $messenger, PhpmailerOauth2PluginManagerInterface $plugin_manager) {
// 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->phpmailerOauth2PluginManager = $plugin_manager;
$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;
}
// Check for basic authentication.
if ($this->config
->get('smtp_authentication_type') === 'basic_auth') {
// 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 != '');
}
else {
$oauth2plugin = $this->phpmailerOauth2PluginManager
->createInstance($this->config
->get('smtp_authentication_type'));
$oauth_options = $oauth2plugin
->getAuthOptions();
$oauth = new OAuth($oauth_options);
$this
->setOAuth($oauth);
$this->AuthType = 'XOAUTH2';
$this->SMTPAuth = TRUE;
}
$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;
}
}