This episode is for members only

Sign up to access "Build An Uptime Monitor with Inertia" right now.

Get started
Already a member? Sign in to continue
Playing
33. Setting up email in Laravel

Episodes

0%
Your progress
  • Total: 4h 59m
  • Played: 0m
  • Remaining: 4h 59m
Join or sign in to track your progress

Transcript

00:00
We're now on to email notifications and there are loads of different ways that we can send email in Laravel,
00:05
all of which is on the documentation. It really depends on what service you want to end up using. However, in this video, we're just going to cover setting up sending emails on a local development and I'm going to show you a couple of solutions.
00:18
The first one is going to be the one that we're going to be using and that is just using a piece of software like Hello, which is just a local app that allows you to send all your emails to into a nice inbox that looks like this.
00:30
So we don't have any in there at the moment, but we'll start to see them roll in. Now, this is my preferred solution, but at the end of the video, I'm going to show you how to do this and log this to your log files just so you can see that the emails are actually being sent
00:44
and then of course you can set this up when you're in production to send to real email addresses. Okay, so we're going to use Hello here just to configure this and the first thing that we're going to do is come over to set up our mail stuff within our EMV file. So let's just go over to our EMV file here
01:02
and let's come down to the mail section. By default, this is set up to mail hog, which is another way that you can send emails locally. This is actually free as well. So you might want to go ahead and look into the installation steps to do that as well.
01:15
So since we're using Hello here, we're going to go ahead and set the mail host to 127.0.0.1. We're going to change the port to 2525. The username here, we're just going to call general. This just puts it into a specific inbox within Hello
01:31
and the password is going to be null, encryption is going to be null and we want to go ahead and choose a from address here, which doesn't really matter. We're just going to leave that hello at example.com. So if you are using Hello, that is how we're going to set this up.
01:44
Otherwise, you want to change your mail mailer to log. We'll take a look at how that works in a bit. Okay, so how do we send an email or create an email within Laravel? Well, we can use the make mail command.
01:55
So let's just create an example email that we're going to go ahead and send. Throughout the course, we're going to go ahead and use the markdown option here to generate out a nice email layout. But for now, let's just go ahead and create one out as it is.
02:10
Okay, so we're going to go ahead and open this example mail up, which now lives in app and mail and we're going to go down and take a look at what we have here. So let's go down.
02:18
We have a constructor so we can pass stuff into here, which is going to be really handy. If an endpoint goes down, of course, we're going to want to send the endpoint through to this
02:26
and we have this envelope method here, which allows us to create a subject and any other information out. Let's just leave that as example now, just so we can see that. And if we go down here, we have a content method,
02:37
which returns this new content object and we have a view that we can potentially use here. So this is the standard way that we would do this. So for example, if you did want to use just a standard view,
02:49
let's go over to our resources section and under our views, let's create an emails or an email folder out and just say example.blade.php. So I'm just going to write this is an example email
03:04
and we're going to go ahead and reference that over here. So that's going to be email example and let's just spell that correctly. There we go.
03:12
Okay, so we can attach things, but we don't need to do that in this case. This email is now good to send. So we're going to keep an eye on our hello inbox just here
03:21
or whatever solution that you're using and let's go over and send this email. So to do this within the terminal, we're just going to run phpr and tinker so we can send this off.
03:31
We're going to go ahead and say mail to and then we're going to choose a user or an email address. So I'm going to go ahead and say user find one. Of course, we're actually going to be sending that to the user within the app,
03:44
but let's go ahead and find that manually for now and we're going to go ahead and say send or more appropriately in our case since we have queue set up. We're actually going to end up using queue.
03:55
Let's go ahead and say send and we're going to new up that example email. So app mail and example and that should be pretty much all we need to send out an email
04:06
and you can see that over in the hello app. We've actually received a new email in here with the body that we just defined in that blade template. Okay, so let's just finally look at what is going to happen
04:17
if we wanted to set this to log. So I'm going to go ahead and open up the Laravel log file, which has a few errors in there. So we're going to get rid of that
04:25
and we're going to go ahead and send that email out again. So let's go over to our terminal. I'm going to exit off of this just to refresh everything and we're going to go back into tinker.
04:34
We're going to resend that email and what we should see is this pulled in. There is and you can see here. We've got all of the information who it's to
04:43
so that's that user that I picked out the subject here and the body. So if you don't have anything that you want to use for local development or you're still deciding feel free
04:52
to just set that to log and at least you will see the emails in your Laravel log file within this location. Okay, I'm going to get rid of that
05:00
and I'm going to switch this back to SMTP so we can send this through hello and we're now pretty much set up very easily to start sending emails.
44 episodes4 hrs 59 mins

Overview

Ready to dive into Inertia? Let's build a real-world app with Laravel, Inertia and Vue! If you're already working with Inertia, you'll pick up some tips and techniques for future projects.

This uptime monitor allows you to create and switch between sites, then add endpoints to monitor with frequency intervals. Using the power of scheduling and queues, it'll automatically alert the email addresses you've added via the UI when an endpoint goes down.

In this course, you'll learn to:

  • Build a real app from scratch with Inertia
  • Work with Laravel queues
  • Perform actions on models at user-defined intervals
  • Work with sub-minute schedules in Laravel
  • Send out channel notifications with Laravel
  • Use API resources to simplify Inertia data
  • Organise apps with events and observers
  • Create modals in Vue
  • Perform inline editing with Inertia forms
Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!