Upload folder via GUI - inc
This commit is contained in:
54
inc/classes/class-smtp.php
Normal file
54
inc/classes/class-smtp.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user