add new PHPMail Wrapper to avoid multiple setting of properties

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2018-12-21 14:49:55 +01:00
parent f9ad392e39
commit 1ba4164028
19 changed files with 329 additions and 407 deletions

View File

@@ -320,31 +320,7 @@ class Cronjob
{
if (Settings::Get('system.send_cron_errors') == '1') {
$_mail = new \PHPMailer\PHPMailer\PHPMailer(true);
$_mail->CharSet = "UTF-8";
if (Settings::Get('system.mail_use_smtp')) {
$_mail->isSMTP();
$_mail->Host = Settings::Get('system.mail_smtp_host');
$_mail->SMTPAuth = Settings::Get('system.mail_smtp_auth') == '1' ? true : false;
$_mail->Username = Settings::Get('system.mail_smtp_user');
$_mail->Password = Settings::Get('system.mail_smtp_passwd');
if (Settings::Get('system.mail_smtp_usetls')) {
$_mail->SMTPSecure = 'tls';
} else {
$_mail->SMTPAutoTLS = false;
}
$_mail->Port = Settings::Get('system.mail_smtp_port');
}
if (\PHPMailer\PHPMailer\PHPMailer::ValidateAddress(Settings::Get('panel.adminmail')) !== false) {
// set return-to address and custom sender-name, see #76
$_mail->SetFrom(Settings::Get('panel.adminmail'), Settings::Get('panel.adminmail_defname'));
if (Settings::Get('panel.adminmail_return') != '') {
$_mail->AddReplyTo(Settings::Get('panel.adminmail_return'), Settings::Get('panel.adminmail_defname'));
}
}
$_mail = new Mailer(true);
$_mailerror = false;
$mailerr_msg = "";
try {

View File

@@ -0,0 +1,43 @@
<?php
namespace Froxlor\System;
use Froxlor\Settings;
class Mailer extends \PHPMailer\PHPMailer\PHPMailer
{
/**
* class construtor
*
* @param string $exceptions
* whether to throw exceptions or not
*
*/
public function __construct($exceptions = false)
{
parent::__construct($exceptions);
$this->CharSet = "UTF-8";
if (Settings::Get('system.mail_use_smtp')) {
$this->isSMTP();
$this->Host = Settings::Get('system.mail_smtp_host');
$this->SMTPAuth = Settings::Get('system.mail_smtp_auth') == '1' ? true : false;
$this->Username = Settings::Get('system.mail_smtp_user');
$this->Password = Settings::Get('system.mail_smtp_passwd');
if (Settings::Get('system.mail_smtp_usetls')) {
$this->SMTPSecure = 'tls';
} else {
$this->SMTPAutoTLS = false;
}
$this->Port = Settings::Get('system.mail_smtp_port');
}
if (self::ValidateAddress(Settings::Get('panel.adminmail')) !== false) {
// set return-to address and custom sender-name, see #76
$this->SetFrom(Settings::Get('panel.adminmail'), Settings::Get('panel.adminmail_defname'));
if (Settings::Get('panel.adminmail_return') != '') {
$this->AddReplyTo(Settings::Get('panel.adminmail_return'), Settings::Get('panel.adminmail_defname'));
}
}
}
}