Send Emails
The Symfony Boilerplate provides the abstract class CreateEmail
.
This class has a method create
, which takes the following arguments:
src/api/src/UseCase/CreateEmail.php
- A recipient - an instance of
User
. - A translation key for the email's subject (see i18n guide for more details).
- A template's path (more on that in the next chapter).
- The template's context (i.e., the data of the template).
note
📣  This class does only create an Email
object (it does not send it.).
You should extend this class to create your emails, for instance:
src/api/src/UseCase/Foo/CreateFooEmail.php
In the use case sending this email, you can inject both the previous class and the MailerInterface
, i.e.:
src/api/src/UseCase/Foo/DoFoo.php
You can then use them as below:
src/api/src/UseCase/Foo/DoFoo.php
note
📣  Always put your classes extending CreateEmail
on the same level as the use case requiring it.