Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
[Mailer] UseaddPart instead ofembed* orattach*.#17372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
39 changes: 27 additions & 12 deletionsmailer.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -446,24 +446,31 @@ result of rendering some template) or PHP resources:: | ||
| File Attachments | ||
| ~~~~~~~~~~~~~~~~ | ||
| Use the ``addPart()`` methodwith a ``BodyFile``toadd files that exist on your file system:: | ||
| $email = (new Email()) | ||
| // ... | ||
| ->addPart(new DataPart(new BodyFile('/path/to/documents/terms-of-use.pdf'))) | ||
| // optionally you can tell email clients to display a custom name for the file | ||
| ->addPart(new DataPart(new BodyFile('/path/to/documents/privacy.pdf', 'Privacy Policy'))) | ||
| // optionally you can provide an explicit MIME type (otherwise it's guessed) | ||
| ->addPart(new DataPart(new BodyFile('/path/to/documents/contract.doc', 'Contract', 'application/msword'))) | ||
| ; | ||
| Alternatively you can attachcontents from a stream by passing it directly to the ``DataPart``:: | ||
| $email = (new Email()) | ||
| // ... | ||
| ->addPart(new DataPart(fopen('/path/to/documents/contract.doc', 'r'))) | ||
| ; | ||
hiddewie marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| .. deprecated:: 6.2 | ||
| In Symfony versions previous to 6.2, the methods ``attachFromPath`` and ``attach`` | ||
| could be used to add attachments. These methods have been deprecated and replaced with | ||
| ``addPart``. | ||
| Embedding Images | ||
| ~~~~~~~~~~~~~~~~ | ||
| @@ -472,25 +479,27 @@ instead of adding them as attachments. When using Twig to render the email | ||
| contents, as explained :ref:`later in this article <mailer-twig-embedding-images>`, | ||
| the images are embedded automatically. Otherwise, you need to embed them manually. | ||
| First, use the ``addPart()`` method to add an image from a | ||
| file or stream:: | ||
| $email = (new Email()) | ||
| // ... | ||
| // get the image contents from a PHP resource | ||
| ->addPart((new DataPart(fopen('/path/to/images/logo.png', 'r'), 'logo', 'image/png'))->asInline()) | ||
| // get the image contents from an existing file | ||
| ->addPart((new DataPart(new BodyFile('/path/to/images/signature.gif', 'footer-signature', 'image/gif')))->asInline()) | ||
| ; | ||
| Use the ``asInline()`` method to embed the content instead of attaching it. | ||
| The second optional argument of both methods is the image name ("Content-ID" in | ||
| the MIME standard). Its value is an arbitrary string used later to reference the | ||
| images inside the HTML contents:: | ||
| $email = (new Email()) | ||
| // ... | ||
| ->addPart((new DataPart(fopen('/path/to/images/logo.png', 'r'), 'logo', 'image/png'))->asInline()) | ||
| ->addPart((new DataPart(new BodyFile('/path/to/images/signature.gif', 'footer-signature', 'image/gif')))->asInline()) | ||
| // reference images using the syntax 'cid:' + "image embed name" | ||
| ->html('<img src="cid:logo"> ... <img src="cid:footer-signature"> ...') | ||
| @@ -503,6 +512,12 @@ images inside the HTML contents:: | ||
| The support of embedded images as HTML backgrounds was introduced in Symfony 6.1. | ||
| .. deprecated:: 6.2 | ||
| In Symfony versions previous to 6.2, the methods ``embedFromPath`` and ``embed`` | ||
| could be used to embed images. These methods have been deprecated and replaced with | ||
| ``addPart`` together with inline ``DataPart``s. | ||
| .. _mailer-configure-email-globally: | ||
| Configuring Emails Globally | ||
| @@ -1489,7 +1504,7 @@ FailedMessageEvent | ||
| { | ||
| // e.g you can get more information on this error when sending an email | ||
| $event->getError(); | ||
| // do something with the message | ||
| } | ||
hiddewie marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.