Miglioramento log email

This commit is contained in:
Thomas Zilio 2018-09-28 15:16:43 +02:00
parent adca751695
commit 22d7bbec33
2 changed files with 21 additions and 9 deletions

View File

@ -440,10 +440,10 @@ if (!empty($operations)) {
foreach ($operations as $operation) { foreach ($operations as $operation) {
echo ' echo '
<span class="label label-success pull-right"> <span class="label label-success pull-right">
'.tr('_EMAIL_ inviata il _DATE_ alle _HOUR_ da _USER_.', [ '.tr('Email "_EMAIL_" inviata il _DATE_ alle _HOUR_ da _USER_.', [
'_EMAIL_' => $operation['email'], '_EMAIL_' => $operation['email'],
'_DATE_' => Translator::dateToLocale($operation['data']), '_DATE_' => Translator::dateToLocale($operation['created_at']),
'_HOUR_' => Translator::timeToLocale($operation['ora']), '_HOUR_' => Translator::timeToLocale($operation['created_at']),
'_USER_' => $operation['user'], '_USER_' => $operation['user'],
]).' ]).'
</span><br>'; </span><br>';

View File

@ -161,9 +161,9 @@ class Mail extends PHPMailer\PHPMailer\PHPMailer
$this->IsSMTP(true); $this->IsSMTP(true);
// Impostazioni di debug // Impostazioni di debug
$this->SMTPDebug = 4; $this->SMTPDebug = App::debug() ? 2: 0;
$this->Debugoutput = function ($str, $level) { $this->Debugoutput = function ($str, $level) {
$this->infos[] = $str; [] = $str;
}; };
// Impostazioni dell'host // Impostazioni dell'host
@ -216,15 +216,27 @@ class Mail extends PHPMailer\PHPMailer\PHPMailer
$this->AltBody = strip_tags($this->Body); $this->AltBody = strip_tags($this->Body);
} }
$exception = null;
try {
$result = parent::send(); $result = parent::send();
} catch (PHPMailer\PHPMailer\Exception $e) {
$result = false;
$exception = $e;
}
$this->SmtpClose(); $this->SmtpClose();
// Segnalazione degli errori // Segnalazione degli errori
if (!$result) {
$logger = logger(); $logger = logger();
foreach ($this->infos as $info) { foreach ($this->infos as $info) {
$logger->addRecord(\Monolog\Logger::ERROR, $info); $logger->addRecord(\Monolog\Logger::ERROR, $info);
} }
}
if (!empty($exception)) {
throw $exception;
}
return $result; return $result;
} }