From d4b0483bc5cce050f03c1ac9e271dbdba89d67c5 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 9 Aug 2022 12:05:38 +0900 Subject: [PATCH 1/2] docs: fix @param type --- system/Email/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/Email/Email.php b/system/Email/Email.php index 55c9c95e2205..0228ae70c946 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -2090,8 +2090,8 @@ protected function getHostname() } /** - * @param array $include List of raw data chunks to include in the output - * Valid options are: 'headers', 'subject', 'body' + * @param array|string $include List of raw data chunks to include in the output + * Valid options are: 'headers', 'subject', 'body' * * @return string */ From 6d51b2c3f1eb140e2c0b079f19dd664b7ae5bb42 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 9 Aug 2022 13:06:38 +0900 Subject: [PATCH 2/2] fix: Email class may not log an error when it fails to send --- system/Email/Email.php | 49 +++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/system/Email/Email.php b/system/Email/Email.php index 0228ae70c946..3ef459a8d08f 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -288,6 +288,13 @@ class Email */ protected $debugMessage = []; + /** + * Raw debug messages + * + * @var string[] + */ + private array $debugMessageRaw = []; + /** * Recipients * @@ -434,16 +441,17 @@ public function initialize($config) */ public function clear($clearAttachments = false) { - $this->subject = ''; - $this->body = ''; - $this->finalBody = ''; - $this->headerStr = ''; - $this->replyToFlag = false; - $this->recipients = []; - $this->CCArray = []; - $this->BCCArray = []; - $this->headers = []; - $this->debugMessage = []; + $this->subject = ''; + $this->body = ''; + $this->finalBody = ''; + $this->headerStr = ''; + $this->replyToFlag = false; + $this->recipients = []; + $this->CCArray = []; + $this->BCCArray = []; + $this->headers = []; + $this->debugMessage = []; + $this->debugMessageRaw = []; $this->setHeader('Date', $this->setDate()); @@ -1658,7 +1666,12 @@ protected function spoolEmail() } if (! $success) { - $this->setErrorMessage(lang('Email.sendFailure' . ($protocol === 'mail' ? 'PHPMail' : ucfirst($protocol)))); + $message = lang('Email.sendFailure' . ($protocol === 'mail' ? 'PHPMail' : ucfirst($protocol))); + + log_message('error', 'Email: ' . $message); + log_message('error', $this->printDebuggerRaw()); + + $this->setErrorMessage($message); return false; } @@ -1937,7 +1950,8 @@ protected function sendCommand($cmd, $data = '') $reply = $this->getSMTPData(); - $this->debugMessage[] = '
' . $cmd . ': ' . $reply . '
'; + $this->debugMessage[] = '
' . $cmd . ': ' . $reply . '
'; + $this->debugMessageRaw[] = $cmd . ': ' . $reply; if ($resp === null || ((int) static::substr($reply, 0, 3) !== $resp)) { $this->setErrorMessage(lang('Email.SMTPError', [$reply])); @@ -2119,12 +2133,21 @@ public function printDebugger($include = ['headers', 'subject', 'body']) return $msg . ($rawData === '' ? '' : '
' . $rawData . '
'); } + /** + * Returns raw debug messages + */ + private function printDebuggerRaw(): string + { + return implode("\n", $this->debugMessageRaw); + } + /** * @param string $msg */ protected function setErrorMessage($msg) { - $this->debugMessage[] = $msg . '
'; + $this->debugMessage[] = $msg . '
'; + $this->debugMessageRaw[] = $msg; } /**