Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/Illuminate/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('/<img.+?src=[\'"]cid:([^\'"]+)[\'"].*?>/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;
}

/**
Expand Down