diff --git a/src/Symfony/Component/Mime/Email.php b/src/Symfony/Component/Mime/Email.php
index 952c7b5c151ca..bfc7c37f1b043 100644
--- a/src/Symfony/Component/Mime/Email.php
+++ b/src/Symfony/Component/Mime/Email.php
@@ -460,8 +460,17 @@ private function prepareParts(): ?array
if (null !== $this->html) {
$htmlPart = new TextPart($html, $this->htmlCharset, 'html');
$html = $htmlPart->getBody();
- preg_match_all('(]*src\s*=\s*(?:([\'"])cid:([^"]+)\\1|cid:([^>\s]+)))i', $html, $names);
- $names = array_filter(array_unique(array_merge($names[2], $names[3])));
+
+ $regexes = [
+ '
]*src\s*=\s*(?:([\'"])cid:([^"]+)\\1|cid:([^>\s]+))',
+ '<\w+\s+[^>]*background\s*=\s*(?:([\'"])cid:([^"]+)\\1|cid:([^>\s]+))',
+ ];
+ $tmpMatches = [];
+ foreach ($regexes as $regex) {
+ preg_match_all('/'.$regex.'/i', $html, $tmpMatches);
+ $names = array_merge($names, $tmpMatches[2], $tmpMatches[3]);
+ }
+ $names = array_filter(array_unique($names));
}
$attachmentParts = $inlineParts = [];
diff --git a/src/Symfony/Component/Mime/Tests/EmailTest.php b/src/Symfony/Component/Mime/Tests/EmailTest.php
index e5b48fe6cabdc..ea06c7f6c12f5 100644
--- a/src/Symfony/Component/Mime/Tests/EmailTest.php
+++ b/src/Symfony/Component/Mime/Tests/EmailTest.php
@@ -351,6 +351,14 @@ 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('