Browse Source

Merge pull request #11149 from obinoob/patch-2

Logging email fails array to string conversion
Mark Story 8 years ago
parent
commit
20840d8152
1 changed files with 12 additions and 1 deletions
  1. 12 1
      src/Mailer/Email.php

+ 12 - 1
src/Mailer/Email.php

@@ -2084,12 +2084,23 @@ class Email implements JsonSerializable, Serializable
         }
         Log::write(
             $config['level'],
-            PHP_EOL . $contents['headers'] . PHP_EOL . PHP_EOL . $contents['message'],
+            PHP_EOL . $this->flatten($contents['headers']) . PHP_EOL . PHP_EOL . $this->flatten($contents['message']),
             $config['scope']
         );
     }
 
     /**
+     * Converts given value to string
+     *
+     * @param string|array $value The value to convert
+     * @return string
+     */
+    protected function flatten($value)
+    {
+        return is_array($value) ? implode(';', $value) : (string)$value;
+    }
+
+    /**
      * Static method to fast create an instance of \Cake\Mailer\Email
      *
      * @param string|array|null $to Address to send (see Cake\Mailer\Email::to()). If null, will try to use 'to' from transport config