WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:00.096 --> 00:00:03.646 align:middle
Hey friends!

00:00:03.916 --> 00:00:05.846 align:middle
Welcome to "Symfony Mailer with Mailtrap"!

00:00:06.256 --> 00:00:09.106 align:middle
I'm Kevin, and I'll be your
postmaster for this course,

00:00:09.306 --> 00:00:13.056 align:middle
which is all about sending beautiful
emails with Symfony's Mailer component,

00:00:13.296 --> 00:00:17.296 align:middle
including adding HTML, CSS -
and configuring for production.

00:00:17.886 --> 00:00:22.366 align:middle
On that note, there are many services you can
use on production to actually send your emails.

00:00:22.786 --> 00:00:26.686 align:middle
This course will focus on one called
Mailtrap: (1) because it's great

00:00:26.906 --> 00:00:30.856 align:middle
and (2) because it offers a
fantastic way to preview your emails.

00:00:31.296 --> 00:00:33.886 align:middle
But don't worry, the concepts
we'll cover are universal

00:00:33.886 --> 00:00:36.056 align:middle
and can be applied to any email service.

00:00:36.656 --> 00:00:37.406 align:middle
And bonus!

00:00:37.656 --> 00:00:41.956 align:middle
We'll also cover how to track
email events like bounces, opens,

00:00:41.956 --> 00:00:47.376 align:middle
and link clicks by leveraging some relatively
new Symfony components: Webhook and RemoteEvent.

00:00:48.006 --> 00:00:52.386 align:middle
Before we start spamming, ahem,
delivering important info via email,

00:00:52.666 --> 00:00:58.166 align:middle
we need to clarify something: Symfony Mailer
is for what's called transactional emails only.

00:00:58.656 --> 00:01:03.066 align:middle
These are user-specific emails that occur
when something specific happens in your app.

00:01:03.456 --> 00:01:08.336 align:middle
Things like: a welcome email after a user
signs up, an order confirmation email

00:01:08.336 --> 00:01:10.876 align:middle
when they place an order, or even emails like a

00:01:10.906 --> 00:01:14.936 align:middle
"your post was upvoted" are all
examples of transactional emails.

00:01:15.536 --> 00:01:18.626 align:middle
Symfony Mailer is not for
bulk or marketing emails.

00:01:18.996 --> 00:01:23.356 align:middle
Because of this, we don't need to worry
about any kind of unsubscribe functionality.

00:01:24.066 --> 00:01:27.376 align:middle
There are specific services for
sending bulk emails or newsletters,

00:01:27.606 --> 00:01:29.536 align:middle
Mailtrap can even do this via their site.

00:01:30.306 --> 00:01:33.466 align:middle
As always, to deliver the most
bang for your screencast buck,

00:01:33.626 --> 00:01:35.366 align:middle
you should totally code along with me!

00:01:35.916 --> 00:01:37.646 align:middle
Download the course code on this page.

00:01:38.106 --> 00:01:41.916 align:middle
When you unzip the file, you'll find a start/
directory with the code we'll start with.

00:01:42.486 --> 00:01:44.326 align:middle
Follow the README.md file
to get the app running.

00:01:44.826 --> 00:01:48.766 align:middle
I've already done this and ran symfony
serve -d to start the web server.

00:01:49.416 --> 00:01:52.266 align:middle
Welcome to "Universal Travel": a travel agency

00:01:52.266 --> 00:01:55.506 align:middle
where users can book trips to
different galactic locations.

00:01:55.956 --> 00:01:57.796 align:middle
Here are the currently available trips.

00:01:58.196 --> 00:02:02.426 align:middle
Users can already book these, but there are
no confirmation emails sent when they do.

00:02:02.916 --> 00:02:03.806 align:middle
We're going to fix that!

00:02:04.346 --> 00:02:06.796 align:middle
If I'm spending thousands of
credits on a trip to Naboo,

00:02:07.046 --> 00:02:09.166 align:middle
I want to know that my reservation
was successful!

00:02:09.686 --> 00:02:12.066 align:middle
Step 1: let's install the Symfony Mailer!

00:02:12.476 --> 00:02:19.286 align:middle
Open your terminal and run: composer
require mailer The Symfony Flex recipe

00:02:19.286 --> 00:02:22.396 align:middle
for mailer is asking us to
install some Docker configuration.

00:02:22.846 --> 00:02:26.706 align:middle
This is for a local SMTP server
to help with previewing emails.

00:02:27.046 --> 00:02:29.316 align:middle
We're going to use Mailtrap
for this so say "no".

00:02:31.956 --> 00:02:32.656 align:middle
Installed!

00:02:33.146 --> 00:02:35.226 align:middle
Run: git status to see what we got.

00:02:36.076 --> 00:02:39.266 align:middle
Looks like the recipe added some
environment variables in .env

00:02:39.646 --> 00:02:43.996 align:middle
and added the mailer configuration
in config/packages/mailer.yaml.

00:02:44.696 --> 00:02:46.686 align:middle
In your IDE, open .env.

00:02:48.066 --> 00:02:51.666 align:middle
The Mailer recipe added this
MAILER_DSN environment variable.

00:02:52.156 --> 00:02:56.526 align:middle
This is a special URL-looking string
that configures your mailer transport:

00:02:56.826 --> 00:03:03.596 align:middle
how your emails are actually sent, like via
SMTP, Mailtrap, etc. The recipe defaults

00:03:03.596 --> 00:03:06.856 align:middle
to null://null and is perfect for
local development and testing.

00:03:07.446 --> 00:03:09.666 align:middle
This transport does nothing
when an email is sent!

00:03:09.986 --> 00:03:13.326 align:middle
It pretends to deliver the email,
but really sends it out an airlock.

00:03:13.776 --> 00:03:15.636 align:middle
We'll preview our emails in a different way.

00:03:16.576 --> 00:03:18.796 align:middle
Ok! We're ready to send our first email!

00:03:19.116 --> 00:03:20.226 align:middle
Let's do that next!

