File tree Expand file tree Collapse file tree 2 files changed +12
-4
lines changed
src/Symfony/Component/Mime Expand file tree Collapse file tree 2 files changed +12
-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 && !$ attachmentParts ) {
428
+ throw new LogicException ('A message must have a text 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 @@ -284,6 +284,10 @@ public function testGenerateBody()
284
284
$ e ->html ('html content ' );
285
285
$ this ->assertEquals (new MixedPart ($ html , $ att ), $ e ->getBody ());
286
286
287
+ $ e = new Email ();
288
+ $ e ->attach ($ file );
289
+ $ this ->assertEquals (new MixedPart ($ att ), $ e ->getBody ());
290
+
287
291
$ e = new Email ();
288
292
$ e ->html ('html content ' );
289
293
$ e ->text ('text content ' );
You can’t perform that action at this time.
0 commit comments