WEBVTT

NOTE Created by CaptionSync from Automatic Sync Technologies www.automaticsync.com

00:00:01.066 --> 00:00:01.836 align:middle
Let's take a trip!

00:00:02.256 --> 00:00:05.006 align:middle
"Visit Krypton", Hopefully
it hasn't been destroyed yet!

00:00:05.416 --> 00:00:07.466 align:middle
Without bothering to check, let's book it!

00:00:07.896 --> 00:00:10.116 align:middle
I'll use name: "Kevin", email:

00:00:10.116 --> 00:00:13.566 align:middle
"kevin@example.com" and just
any date in the future.

00:00:14.326 --> 00:00:15.296 align:middle
Hit "Book Trip".

00:00:16.216 --> 00:00:18.016 align:middle
This is the "booking details" page.

00:00:18.336 --> 00:00:21.926 align:middle
Note the URL: it has a unique
token specific to this booking.

00:00:22.416 --> 00:00:26.586 align:middle
If a user needs to come back here later,
currently, they need to bookmark this page

00:00:26.586 --> 00:00:28.926 align:middle
or Slack themselves the URL if they're like me.

00:00:29.286 --> 00:00:33.816 align:middle
Lame! Let's send them a confirmation
email that includes a link to this page.

00:00:34.306 --> 00:00:36.896 align:middle
I want this to happen after
the booking is first saved.

00:00:37.266 --> 00:00:39.776 align:middle
Open TripController and find the show() method.

00:00:40.386 --> 00:00:44.756 align:middle
This makes the booking: if the form
is valid, create or fetch a customer

00:00:44.916 --> 00:00:47.406 align:middle
and create a booking for this customer and trip.

00:00:48.036 --> 00:00:50.326 align:middle
Then we redirect to the booking details page.

00:00:50.616 --> 00:00:54.836 align:middle
Delightfully boring so far, just
how I like my code, and weekends.

00:00:55.556 --> 00:00:58.066 align:middle
I want to send an email after
the booking is created.

00:00:58.616 --> 00:01:02.246 align:middle
Give yourself some room by moving
each method argument to its own line.

00:01:07.026 --> 00:01:13.496 align:middle
Then, add MailerInterface $mailer to get the
main service for sending emails: After flush(),

00:01:13.546 --> 00:01:17.416 align:middle
which inserts the booking into the
database, create a new email object:

00:01:17.416 --> 00:01:21.886 align:middle
$email = new Email() (the one
from Symfony\Component\Mime).

00:01:21.886 --> 00:01:26.056 align:middle
Wrap it in parentheses so we can chain methods.

00:01:26.976 --> 00:01:28.466 align:middle
So what does every email need?

00:01:28.896 --> 00:01:35.226 align:middle
A from email address: -&gt;from() how
about info@univeral-travel.com.

00:01:35.756 --> 00:01:40.996 align:middle
A to email address: -&gt;to($customer-&gt;getEmail()).

00:01:41.616 --> 00:01:45.366 align:middle
Now, the subject: -&gt;subject('Booking
Confirmation').

00:01:46.096 --> 00:01:51.376 align:middle
And finally, the email needs a body:
-&gt;text('Your booking has been confirmed') -

00:01:51.896 --> 00:01:57.696 align:middle
good enough for now: Finish with
$mailer-&gt;send($email): Let's test this out!

00:01:58.236 --> 00:02:01.266 align:middle
Back in our app, go back to
the homepage and choose a trip.

00:02:02.446 --> 00:02:06.626 align:middle
For the name, use "Steve",
email, "steve@minecraft.com",

00:02:07.076 --> 00:02:09.346 align:middle
any date in the future, and book the trip.

00:02:10.456 --> 00:02:13.796 align:middle
Ok... this page looks exactly
the same as before.

00:02:14.186 --> 00:02:15.236 align:middle
Was an email sent?

00:02:15.766 --> 00:02:18.726 align:middle
Nothing in the web debug
toolbar seems to indicate this...

00:02:19.286 --> 00:02:23.496 align:middle
The email was actually sent on the
previous request - the form submit.

00:02:24.116 --> 00:02:26.686 align:middle
That controller then redirected us to this page.

00:02:26.926 --> 00:02:31.926 align:middle
But the web debug toolbar gives us a shortcut
to access the profiler for the previous request:

00:02:32.386 --> 00:02:35.886 align:middle
hover over 200 and click the
profiler link to get there.

00:02:37.006 --> 00:02:39.966 align:middle
Check out the sidebar - we
have a new "Emails" tab!

00:02:40.136 --> 00:02:42.106 align:middle
And it shows 1 email was sent.

00:02:42.486 --> 00:02:43.126 align:middle
We did it!

00:02:43.526 --> 00:02:45.096 align:middle
Click it, and here's our email!

00:02:45.526 --> 00:02:49.516 align:middle
The from, to, subject, and
body are all what we expect.

00:02:50.146 --> 00:02:54.646 align:middle
Remember, we're using the null mailer
transport, so this email wasn't actually sent,

00:02:55.026 --> 00:02:57.796 align:middle
but it's super cool we can still
preview it in the profiler!

00:02:58.256 --> 00:02:58.686 align:middle
Though ...

00:02:58.856 --> 00:03:00.406 align:middle
I think we both know this email...

00:03:00.406 --> 00:03:01.866 align:middle
is... pretty crappy.

00:03:02.426 --> 00:03:04.336 align:middle
It doesn't give any of the useful info!

00:03:04.806 --> 00:03:09.926 align:middle
No URL to the booking details page,
no destination, no date, no nothing!

00:03:10.366 --> 00:03:14.626 align:middle
It's so useless, I'm glad the null transport
is just throwing it out the space window.

00:03:15.186 --> 00:03:16.466 align:middle
Let's fix that next!

