diff --git a/src/Symfony/Component/Mime/Email.php b/src/Symfony/Component/Mime/Email.php index 7a7a0db32e167..0d72672451df8 100644 --- a/src/Symfony/Component/Mime/Email.php +++ b/src/Symfony/Component/Mime/Email.php @@ -480,6 +480,12 @@ private function prepareParts(): ?array foreach ($this->attachments as $attachment) { foreach ($names as $name) { if (isset($attachment['part'])) { + if ('inline' === $attachment['part']->getPreparedHeaders()->getHeaderBody('Content-Disposition')) { + $inlineParts[] = $attachment['part']; + + continue 2; + } + continue; } if ($name !== $attachment['name']) { diff --git a/src/Symfony/Component/Mime/Tests/EmailTest.php b/src/Symfony/Component/Mime/Tests/EmailTest.php index 230df0791e15b..e02de4701085e 100644 --- a/src/Symfony/Component/Mime/Tests/EmailTest.php +++ b/src/Symfony/Component/Mime/Tests/EmailTest.php @@ -344,6 +344,12 @@ public function testGenerateBody() // 2 parts only, not 3 (text + embedded image once) $this->assertCount(2, $parts = $body->getParts()); $this->assertStringMatchesFormat('html content ', $parts[0]->bodyToString()); + + $e = (new Email())->from('me@example.com')->to('you@example.com'); + $e->html('html content '); + $e->attachPart((new DataPart($image, 'test.gif'))->asInline()); + $body = $e->getBody(); + $this->assertInstanceOf(RelatedPart::class, $body); } public function testAttachments()