diff --git a/src/Illuminate/Mail/Mailer.php b/src/Illuminate/Mail/Mailer.php index 07187d0483a9..132d95683754 100755 --- a/src/Illuminate/Mail/Mailer.php +++ b/src/Illuminate/Mail/Mailer.php @@ -253,7 +253,38 @@ public function render($view, array $data = []) $data['message'] = $this->createMessage(); - return $this->renderView($view ?: $plain, $data); + return $this->replaceEmbeddedAttachments( + $this->renderView($view ?: $plain, $data), + $data['message']->getSymfonyMessage()->getAttachments() + ); + } + + /** + * Replace the embedded image attachments with raw, inline image data for browser rendering. + * + * @param string $renderedView + * @param array $attachments + * @return string + */ + protected function replaceEmbeddedAttachments(string $renderedView, array $attachments) + { + if (preg_match_all('//i', $renderedView, $matches)) { + foreach (array_unique($matches[1]) as $image) { + foreach ($attachments as $attachment) { + if ($attachment->getFilename() === $image) { + $renderedView = str_replace( + 'cid:'.$image, + 'data:'.$attachment->getContentType().';base64,'.$attachment->bodyToString(), + $renderedView + ); + + break; + } + } + } + } + + return $renderedView; } /**