55 lines
1.7 KiB
PHP
55 lines
1.7 KiB
PHP
<?php
|
|
if(!defined('ABSPATH')) exit;
|
|
|
|
class WMF_SMTP {
|
|
|
|
private static $instance = null;
|
|
|
|
public static function instance() {
|
|
if(is_null(self::$instance)) {
|
|
self::$instance = new self();
|
|
self::$instance->hook();
|
|
}
|
|
return self::$instance;
|
|
}
|
|
|
|
public function hook() {
|
|
$opts = get_option('wmf_global_settings', array());
|
|
if(!empty($opts['smtp_enabled']) && $opts['smtp_enabled'] === '1' && !empty($opts['smtp_host'])) {
|
|
add_action('phpmailer_init', array($this, 'configure_smtp'));
|
|
}
|
|
}
|
|
|
|
public function configure_smtp($phpmailer) {
|
|
$opts = get_option('wmf_global_settings', array());
|
|
if(empty($opts['smtp_host'])) return;
|
|
|
|
$phpmailer->isSMTP();
|
|
$phpmailer->Host = $opts['smtp_host'];
|
|
$phpmailer->Port = intval($opts['smtp_port'] ?? 587);
|
|
$phpmailer->SMTPSecure = $opts['smtp_enc'] ?? 'tls';
|
|
|
|
if(!empty($opts['smtp_user'])) {
|
|
$phpmailer->SMTPAuth = true;
|
|
$phpmailer->Username = $opts['smtp_user'];
|
|
$phpmailer->Password = $opts['smtp_pass'] ?? '';
|
|
} else {
|
|
$phpmailer->SMTPAuth = false;
|
|
}
|
|
|
|
// From-Adresse global setzen falls nicht per Mail-Header gesetzt
|
|
if(!empty($opts['from_email'])) {
|
|
$phpmailer->From = $opts['from_email'];
|
|
$phpmailer->FromName = $opts['from_name'] ?? get_bloginfo('name');
|
|
}
|
|
|
|
$phpmailer->SMTPOptions = array(
|
|
'ssl' => array(
|
|
'verify_peer' => false,
|
|
'verify_peer_name' => false,
|
|
'allow_self_signed' => true,
|
|
)
|
|
);
|
|
}
|
|
}
|