10000 Create mailBody with only attachments part present · srsbiz/symfony@0047cc1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0047cc1

Browse files
committed
Create mailBody with only attachments part present
Fixes symfony#32811
1 parent 85827f3 commit 0047cc1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Symfony/Component/Mime/Email.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,12 +423,12 @@ public function getBody(): AbstractPart
423423
*/
424424
private function generateBody(): AbstractPart
425425
{
426-
if (null === $this->text && null === $this->html) {
427-
throw new LogicException('A message must have a text and/or an HTML part.');
426+
[$htmlPart, $attachmentParts, $inlineParts] = $this->prepareParts();
427+
if (null === $this->text && null === $this->html && empty($attachmentParts)) {
428+
throw new LogicException('A message must have a text and/or an HTML part or attachments.');
428429
}
429430

430431
$part = null === $this->text ? null : new TextPart($this->text, $this->textCharset);
431-
[$htmlPart, $attachmentParts, $inlineParts] = $this->prepareParts();
432432
if (null !== $htmlPart) {
433433
if (null !== $part) {
434434
$part = new AlternativePart($part, $htmlPart);
@@ -442,7 +442,11 @@ private function generateBody(): AbstractPart
442442
}
443443

444444
if ($attachmentParts) {
445-
$part = new MixedPart($part, ...$attachmentParts);
445+
if ($part) {
446+
$part = new MixedPart($part, ...$attachmentParts);
447+
} else {
448+
$part = new MixedPart(...$attachmentParts);
449+
}
446450
}
447451

448452
return $part;

src/Symfony/Component/Mime/Tests/EmailTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ public function testGenerateBodyThrowsWhenEmptyBody()
238238
(new Email())->getBody();
239239
}
240240

241+
public function testGenerateBodyDoesNotThrowWhenAttachmentsPresent()
242+
{
243+
$body = (new Email())->attachFromPath(__FILE__)->getBody();
244+
$this->assertNotEmpty($body);
245+
}
246+
241247
public function testGetBody()
242248
{
243249
$e = new Email();

0 commit comments

Comments
 (0)
0