diff --git a/system/Email/Email.php b/system/Email/Email.php
index 55c9c95e2205..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[] = '<pre>' . $cmd . ': ' . $reply . '</pre>';
+        $this->debugMessage[]    = '<pre>' . $cmd . ': ' . $reply . '</pre>';
+        $this->debugMessageRaw[] = $cmd . ': ' . $reply;
 
         if ($resp === null || ((int) static::substr($reply, 0, 3) !== $resp)) {
             $this->setErrorMessage(lang('Email.SMTPError', [$reply]));
@@ -2090,8 +2104,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
      */
@@ -2119,12 +2133,21 @@ public function printDebugger($include = ['headers', 'subject', 'body'])
         return $msg . ($rawData === '' ? '' : '<pre>' . $rawData . '</pre>');
     }
 
+    /**
+     * Returns raw debug messages
+     */
+    private function printDebuggerRaw(): string
+    {
+        return implode("\n", $this->debugMessageRaw);
+    }
+
     /**
      * @param string $msg
      */
     protected function setErrorMessage($msg)
     {
-        $this->debugMessage[] = $msg . '<br />';
+        $this->debugMessage[]    = $msg . '<br />';
+        $this->debugMessageRaw[] = $msg;
     }
 
     /**