@@ -446,24 +446,31 @@ result of rendering some template) or PHP resources::
446
446
File Attachments
447
447
~~~~~~~~~~~~~~~~
448
448
449
- Use the ``attachFromPath () `` method to attach files that exist on your file system::
449
+ Use the ``addPart () `` method with a `` BodyFile `` to add files that exist on your file system::
450
450
451
451
$email = (new Email())
452
452
// ...
453
- ->attachFromPath( '/path/to/documents/terms-of-use.pdf')
453
+ ->addPart(new DataPart(new BodyFile( '/path/to/documents/terms-of-use.pdf')) )
454
454
// optionally you can tell email clients to display a custom name for the file
455
- ->attachFromPath( '/path/to/documents/privacy.pdf', 'Privacy Policy')
455
+ ->addPart(new DataPart(new BodyFile( '/path/to/documents/privacy.pdf', 'Privacy Policy')) )
456
456
// optionally you can provide an explicit MIME type (otherwise it's guessed)
457
- ->attachFromPath( '/path/to/documents/contract.doc', 'Contract', 'application/msword')
457
+ ->addPart(new DataPart(new BodyFile( '/path/to/documents/contract.doc', 'Contract', 'application/msword')) )
458
458
;
459
459
460
- Alternatively you can use the `` attach() `` method to attach contents from a stream::
460
+ Alternatively you can attach contents from a stream by passing it directly to the `` DataPart `` ::
461
461
462
462
$email = (new Email())
463
463
// ...
464
- ->attach( fopen('/path/to/documents/contract.doc', 'r'))
464
+ ->addPart(new DataPart( fopen('/path/to/documents/contract.doc', 'r') ))
465
465
;
466
466
467
+ .. deprecated :: 6.2
468
+
469
+ In Symfony versions previous to 6.2, the methods ``attachFromPath `` and ``attach ``
470
+ could be used to add attachments. These methods have been deprecated and replaced with
471
+ ``addPart ``.
472
+
473
+
467
474
Embedding Images
468
475
~~~~~~~~~~~~~~~~
469
476
@@ -472,25 +479,27 @@ instead of adding them as attachments. When using Twig to render the email
472
479
contents, as explained :ref: `later in this article <mailer-twig-embedding-images >`,
473
480
the images are embedded automatically. Otherwise, you need to embed them manually.
474
481
475
- First, use the ``embed() `` or `` embedFromPath () `` method to add an image from a
482
+ First, use the ``addPart () `` method to add an image from a
476
483
file or stream::
477
484
478
485
$email = (new Email())
479
486
// ...
480
487
// get the image contents from a PHP resource
481
- ->embed( fopen('/path/to/images/logo.png', 'r'), 'logo', 'image/png')
488
+ ->addPart((new DataPart( fopen('/path/to/images/logo.png', 'r'), 'logo', 'image/png'))->asInline() )
482
489
// get the image contents from an existing file
483
- ->embedFromPath( '/path/to/images/signature.gif', 'footer-signature', 'image/gif')
490
+ ->addPart((new DataPart(new BodyFile( '/path/to/images/signature.gif', 'footer-signature', 'image/gif')))->asInline() )
484
491
;
485
492
493
+ Use the ``asInline() `` method to embed the content instead of attaching it.
494
+
486
495
The second optional argument of both methods is the image name ("Content-ID" in
487
496
the MIME standard). Its value is an arbitrary string used later to reference the
488
497
images inside the HTML contents::
489
498
490
499
$email = (new Email())
491
500
// ...
492
- ->embed( fopen('/path/to/images/logo.png', 'r'), 'logo', 'image/png')
493
- ->embedFromPath( '/path/to/images/signature.gif', 'footer-signature', 'image/gif')
501
+ ->addPart((new DataPart( fopen('/path/to/images/logo.png', 'r'), 'logo', 'image/png'))->asInline() )
502
+ ->addPart((new DataPart(new BodyFile( '/path/to/images/signature.gif', 'footer-signature', 'image/gif')))->asInline() )
494
503
495
504
// reference images using the syntax 'cid:' + "image embed name"
496
505
->html('<img src="cid:logo"> ... <img src="cid:footer-signature"> ...')
@@ -503,6 +512,12 @@ images inside the HTML contents::
503
512
504
513
The support of embedded images as HTML backgrounds was introduced in Symfony 6.1.
505
514
515
+ .. deprecated :: 6.2
516
+
517
+ In Symfony versions previous to 6.2, the methods ``embedFromPath `` and ``embed ``
518
+ could be used to embed images. These methods have been deprecated and replaced with
519
+ ``addPart `` together with inline ``DataPart``s.
520
+
506
521
.. _mailer-configure-email-globally:
507
522
508
523
Configuring Emails Globally
0 commit comments