File tree Expand file tree Collapse file tree 1 file changed +26
-10
lines changed Expand file tree Collapse file tree 1 file changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -114,16 +114,6 @@ an email is pretty straightforward::
114
114
),
115
115
'text/html'
116
116
)
117
- /*
118
- * If you also want to include a plaintext version of the message
119
- ->addPart(
120
- $this->renderView(
121
- 'Emails/registration.txt.twig',
122
- ['name' => $name]
123
- ),
124
- 'text/plain'
125
- )
126
- */
127
117
;
128
118
129
119
$mailer->send($message);
@@ -134,6 +124,32 @@ an email is pretty straightforward::
134
124
return $this->render(...);
135
125
}
136
126
127
+ If you want, you can also include a plaintext version of the message:
128
+
129
+ .. code-block :: diff
130
+
131
+ $message = (new \Swift_Message('Hello Email'))
132
+ ->setFrom('send@example.com')
133
+ ->setTo('recipient@example.com')
134
+ ->setBody(
135
+ $this->renderView(
136
+ // app/Resources/views/Emails/registration.html.twig
137
+ 'Emails/registration.html.twig',
138
+ ['name' => $name]
139
+ ),
140
+ 'text/html'
141
+ )
142
+ + ->addPart(
143
+ + $this->renderView(
144
+ + 'Emails/registration.txt.twig',
145
+ + ['name' => $name]
146
+ + ),
147
+ + 'text/plain'
148
+ + )
149
+ ;
150
+
151
+ $mailer->send($message);
152
+
137
153
To keep things decoupled, the email body has been stored in a template and
138
154
rendered with the ``renderView() `` method. The ``registration.html.twig ``
139
155
template might look something like this:
You can’t perform that action at this time.
0 commit comments