From 22d7bbec3303cbc81ef43321e01365a36261a58c Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Fri, 28 Sep 2018 15:16:43 +0200 Subject: [PATCH] Miglioramento log email --- modules/fatture/edit.php | 6 +++--- src/Mail.php | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/modules/fatture/edit.php b/modules/fatture/edit.php index d3b730b27..031426ef2 100644 --- a/modules/fatture/edit.php +++ b/modules/fatture/edit.php @@ -440,10 +440,10 @@ if (!empty($operations)) { foreach ($operations as $operation) { echo ' - '.tr('_EMAIL_ inviata il _DATE_ alle _HOUR_ da _USER_.', [ + '.tr('Email "_EMAIL_" inviata il _DATE_ alle _HOUR_ da _USER_.', [ '_EMAIL_' => $operation['email'], - '_DATE_' => Translator::dateToLocale($operation['data']), - '_HOUR_' => Translator::timeToLocale($operation['ora']), + '_DATE_' => Translator::dateToLocale($operation['created_at']), + '_HOUR_' => Translator::timeToLocale($operation['created_at']), '_USER_' => $operation['user'], ]).'
'; diff --git a/src/Mail.php b/src/Mail.php index 868d1c4c9..0fb45032e 100644 --- a/src/Mail.php +++ b/src/Mail.php @@ -161,9 +161,9 @@ class Mail extends PHPMailer\PHPMailer\PHPMailer $this->IsSMTP(true); // Impostazioni di debug - $this->SMTPDebug = 4; + $this->SMTPDebug = App::debug() ? 2: 0; $this->Debugoutput = function ($str, $level) { - $this->infos[] = $str; + [] = $str; }; // Impostazioni dell'host @@ -216,14 +216,26 @@ class Mail extends PHPMailer\PHPMailer\PHPMailer $this->AltBody = strip_tags($this->Body); } - $result = parent::send(); + $exception = null; + try { + $result = parent::send(); + } catch (PHPMailer\PHPMailer\Exception $e) { + $result = false; + $exception = $e; + } $this->SmtpClose(); // Segnalazione degli errori - $logger = logger(); - foreach ($this->infos as $info) { - $logger->addRecord(\Monolog\Logger::ERROR, $info); + if (!$result) { + $logger = logger(); + foreach ($this->infos as $info) { + $logger->addRecord(\Monolog\Logger::ERROR, $info); + } + } + + if (!empty($exception)) { + throw $exception; } return $result;