Skip to content

Commit 2b79368

Browse files
authored
Fix: multi-line embedded image replacement in mail views (#56828)
1 parent b00bcee commit 2b79368

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/Illuminate/Mail/Mailer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public function render($view, array $data = [])
267267
*/
268268
protected function replaceEmbeddedAttachments(string $renderedView, array $attachments)
269269
{
270-
if (preg_match_all('/<img.+?src=[\'"]cid:([^\'"]+)[\'"].*?>/i', $renderedView, $matches)) {
270+
if (preg_match_all('/<img.+?src=[\'"]cid:([^\'"]+)[\'"].*?>/is', $renderedView, $matches)) {
271271
foreach (array_unique($matches[1]) as $image) {
272272
foreach ($attachments as $attachment) {
273273
if ($attachment->getFilename() === $image) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Embed multiline content: <img
2+
src="{{ $message->embedData('foo', 'foo.jpg', 'image/png') }}"
3+
alt="multiline image"
4+
>

tests/Integration/Mail/SendingMarkdownMailTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ public function testEmbedData()
7979
EOT, $email);
8080
}
8181

82+
public function testEmbedMultilineImage()
83+
{
84+
Mail::to('test@mail.com')->send($mailable = new EmbedMultilineMailable());
85+
86+
$html = html_entity_decode($mailable->render());
87+
88+
$this->assertStringContainsString('Embed multiline content: <img', $html);
89+
$this->assertStringContainsString('alt="multiline image"', $html);
90+
$this->assertStringContainsString('data:image/png;base64', $html);
91+
$this->assertStringNotContainsString('cid:foo.jpg', $html);
92+
}
93+
8294
public function testMessageAsPublicPropertyMayBeDefinedAsViewData()
8395
{
8496
Mail::to('test@mail.com')->send($mailable = new MessageAsPublicPropertyMailable());
@@ -190,6 +202,23 @@ public function content()
190202
}
191203
}
192204

205+
class EmbedMultilineMailable extends Mailable
206+
{
207+
public function envelope()
208+
{
209+
return new Envelope(
210+
subject: 'My basic title',
211+
);
212+
}
213+
214+
public function content()
215+
{
216+
return new Content(
217+
markdown: 'embed-multiline',
218+
);
219+
}
220+
}
221+
193222
class EmbedDataMailable extends Mailable
194223
{
195224
public function envelope()

0 commit comments

Comments
 (0)