Skip to content

Commit 8f13821

Browse files
committed
Use diff instead of code comment
1 parent 790468f commit 8f13821

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

email.rst

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,6 @@ an email is pretty straightforward::
114114
),
115115
'text/html'
116116
)
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-
*/
127117
;
128118

129119
$mailer->send($message);
@@ -134,6 +124,32 @@ an email is pretty straightforward::
134124
return $this->render(...);
135125
}
136126

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+
137153
To keep things decoupled, the email body has been stored in a template and
138154
rendered with the ``renderView()`` method. The ``registration.html.twig``
139155
template might look something like this:

0 commit comments

Comments
 (0)