@@ -448,13 +448,17 @@ File Attachments
448
448
449
449
Use the ``addPart() `` method with a ``BodyFile `` to add files that exist on your file system::
450
450
451
+ use Symfony\Component\Mime\Part\DataPart;
452
+ use Symfony\Component\Mime\Part\File;
453
+ // ...
454
+
451
455
$email = (new Email())
452
456
// ...
453
- ->addPart(new DataPart(new BodyFile ('/path/to/documents/terms-of-use.pdf')))
457
+ ->addPart(new DataPart(new File ('/path/to/documents/terms-of-use.pdf')))
454
458
// optionally you can tell email clients to display a custom name for the file
455
- ->addPart(new DataPart(new BodyFile ('/path/to/documents/privacy.pdf', 'Privacy Policy') ))
459
+ ->addPart(new DataPart(new File ('/path/to/documents/privacy.pdf') , 'Privacy Policy'))
456
460
// optionally you can provide an explicit MIME type (otherwise it's guessed)
457
- ->addPart(new DataPart(new BodyFile ('/path/to/documents/contract.doc', 'Contract', 'application/msword') ))
461
+ ->addPart(new DataPart(new File ('/path/to/documents/contract.doc') , 'Contract', 'application/msword'))
458
462
;
459
463
460
464
Alternatively you can attach contents from a stream by passing it directly to the ``DataPart `` ::
@@ -486,7 +490,7 @@ file or stream::
486
490
// get the image contents from a PHP resource
487
491
->addPart((new DataPart(fopen('/path/to/images/logo.png', 'r'), 'logo', 'image/png'))->asInline())
488
492
// get the image contents from an existing file
489
- ->addPart((new DataPart(new BodyFile ('/path/to/images/signature.gif', 'footer-signature', 'image/gif') ))->asInline())
493
+ ->addPart((new DataPart(new File ('/path/to/images/signature.gif') , 'footer-signature', 'image/gif'))->asInline())
490
494
;
491
495
492
496
Use the ``asInline() `` method to embed the content instead of attaching it.
@@ -498,7 +502,7 @@ images inside the HTML contents::
498
502
$email = (new Email())
499
503
// ...
500
504
->addPart((new DataPart(fopen('/path/to/images/logo.png', 'r'), 'logo', 'image/png'))->asInline())
501
- ->addPart((new DataPart(new BodyFile ('/path/to/images/signature.gif', 'footer-signature', 'image/gif') ))->asInline())
505
+ ->addPart((new DataPart(new File ('/path/to/images/signature.gif') , 'footer-signature', 'image/gif'))->asInline())
502
506
503
507
// reference images using the syntax 'cid:' + "image embed name"
504
508
->html('<img src="cid:logo"> ... <img src="cid:footer-signature"> ...')
0 commit comments