File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed
src/Symfony/Component/Mime Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -423,12 +423,12 @@ public function getBody(): AbstractPart
423
423
*/
424
424
private function generateBody (): AbstractPart
425
425
{
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. ' );
428
429
}
429
430
430
431
$ part = null === $ this ->text ? null : new TextPart ($ this ->text , $ this ->textCharset );
431
- [$ htmlPart , $ attachmentParts , $ inlineParts ] = $ this ->prepareParts ();
432
432
if (null !== $ htmlPart ) {
433
433
if (null !== $ part ) {
434
434
$ part = new AlternativePart ($ part , $ htmlPart );
@@ -442,7 +442,11 @@ private function generateBody(): AbstractPart
442
442
}
443
443
444
444
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
+ }
446
450
}
447
451
448
452
return $ part ;
Original file line number Diff line number Diff line change @@ -238,6 +238,12 @@ public function testGenerateBodyThrowsWhenEmptyBody()
238
238
(new Email ())->getBody ();
239
239
}
240
240
241
+ public function testGenerateBodyDoesNotThrowWhenAttachmentsPresent ()
242
+ {
243
+ $ body = (new Email ())->attachFromPath (__FILE__ )->getBody ();
244
+ $ this ->assertNotEmpty ($ body );
245
+ }
246
+
241
247
public function testGetBody ()
242
248
{
243
249
$ e = new Email ();
You can’t perform that action at this time.
0 commit comments