Skip to content

Commit 3921d70

Browse files
committed
minor #4918 Quick proofread of the email cookbook (weaverryan)
This PR was merged into the 2.3 branch. Discussion ---------- Quick proofread of the email cookbook Hi guys! | Q | A | ------------- | --- | Doc fix? | no | New docs? | no | Applies to | 2.3+ | Fixed tickets | n/a Pretty simple. The motivation was to show an example of the template that uses the new `absolute_url` function for 2.7. But then I wanted to change other stuff. So, after this is merged, I can make another PR for that. Thanks! Commits ------- d32c51c Fixing typo thanks to xabbuh 5207800 Adding reference link 299ead1 Quick proofread of the email cookbook
2 parents 418a73b + d32c51c commit 3921d70

File tree

2 files changed

+48
-41
lines changed

2 files changed

+48
-41
lines changed

best_practices/configuration.rst

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ and security credentials) and different environments (development, production).
66
That's why Symfony recommends that you split the application configuration into
77
three parts.
88

9+
.. _config-parameters.yml:
10+
911
Infrastructure-Related Configuration
1012
------------------------------------
1113

cookbook/email/email.rst

+46-41
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,36 @@ How to Send an Email
77
Sending emails is a classic task for any web application and one that has
88
special complications and potential pitfalls. Instead of recreating the wheel,
99
one solution to send emails is to use the SwiftmailerBundle, which leverages
10-
the power of the `Swift Mailer`_ library.
11-
12-
.. note::
13-
14-
Don't forget to enable the bundle in your kernel before using it::
15-
16-
public function registerBundles()
17-
{
18-
$bundles = array(
19-
// ...
20-
21-
new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
22-
);
23-
24-
// ...
25-
}
10+
the power of the `Swift Mailer`_ library. This bundle comes with the Symfony
11+
Standard Edition.
2612

2713
.. _swift-mailer-configuration:
2814

2915
Configuration
3016
-------------
3117

32-
Before using Swift Mailer, be sure to include its configuration. The only
33-
mandatory configuration parameter is ``transport``:
18+
To use Swift Mailer, you'll need to configure it for your mail server.
19+
20+
.. tip::
21+
22+
Instead of setting up/using your own mail server, you may want to use
23+
a hosted mail provider such as `Mandrill`_, `SendGrid`_, `Amazon SES`_
24+
or others. These give you an SMTP server, username and password (sometimes
25+
called keys) that can be used with the Swift Mailer configuration.
26+
27+
In a standard Symfony installation, some ``swiftmailer`` configuration is
28+
already included:
3429

3530
.. configuration-block::
3631

3732
.. code-block:: yaml
3833
3934
# app/config/config.yml
4035
swiftmailer:
41-
transport: smtp
42-
encryption: ssl
43-
auth_mode: login
44-
host: smtp.gmail.com
45-
username: your_username
46-
password: your_password
36+
transport: "%mailer_transport%"
37+
host: "%mailer_host%"
38+
username: "%mailer_user%"
39+
password: "%mailer_password%"
4740
4841
.. code-block:: xml
4942
@@ -55,27 +48,24 @@ mandatory configuration parameter is ``transport``:
5548
-->
5649
5750
<swiftmailer:config
58-
transport="smtp"
59-
encryption="ssl"
60-
auth-mode="login"
61-
host="smtp.gmail.com"
62-
username="your_username"
63-
password="your_password" />
51+
transport="%mailer_transport%"
52+
host="%mailer_host%"
53+
username="%mailer_user%"
54+
password="%mailer_password%" />
6455
6556
.. code-block:: php
6657
6758
// app/config/config.php
6859
$container->loadFromExtension('swiftmailer', array(
69-
'transport' => "smtp",
70-
'encryption' => "ssl",
71-
'auth_mode' => "login",
72-
'host' => "smtp.gmail.com",
73-
'username' => "your_username",
74-
'password' => "your_password",
60+
'transport' => "%mailer_transport%",
61+
'host' => "%mailer_host%",
62+
'username' => "%mailer_user%",
63+
'password' => "%mailer_password%",
7564
));
7665
77-
The majority of the Swift Mailer configuration deals with how the messages
78-
themselves should be delivered.
66+
These values (e.g. ``%mailer_transport%``), are reading from the parameters
67+
that are set in the :ref:`parameters.yml <config-parameters.yml>` file. You
68+
can modify the values in that file, or set the values directly here.
7969

8070
The following configuration attributes are available:
8171

@@ -105,15 +95,27 @@ an email is pretty straightforward::
10595
{
10696
$mailer = $this->get('mailer');
10797
$message = $mailer->createMessage()
108-
->setSubject('Hello Email')
98+
->setSubject('You have Completed Registration!')
10999
->setFrom('[email protected]')
110100
->setTo('[email protected]')
111101
->setBody(
112102
$this->renderView(
113-
'HelloBundle:Hello:email.txt.twig',
103+
// app/Resources/views/Emails/registration.html.twig
104+
'Emails/registration.html.twig',
105+
array('name' => $name)
106+
),
107+
'text/html'
108+
)
109+
/*
110+
* If you also want to include a plaintext version of the message
111+
->addPart(
112+
$this->renderView(
113+
'Emails/registration.txt.twig',
114114
array('name' => $name)
115-
)
115+
),
116+
'text/plain'
116117
)
118+
*/
117119
;
118120
$mailer->send($message);
119121

@@ -138,3 +140,6 @@ of `Creating Messages`_ in great detail in its documentation.
138140

139141
.. _`Swift Mailer`: http://swiftmailer.org/
140142
.. _`Creating Messages`: http://swiftmailer.org/docs/messages.html
143+
.. _`Mandrill`: https://mandrill.com/
144+
.. _`SendGrid`: https://sendgrid.com/
145+
.. _`Amazon SES`: http://aws.amazon.com/ses/

0 commit comments

Comments
 (0)