This episode is for members only

Sign up to access "Build a Referral System with Laravel" right now.

Get started
Already a member? Sign in to continue
Playing
22. Sending the payout email

Transcript

00:00
Okay let's just quickly look at how we send the referral payout email to an admin and then we will look in the next episode how to generate the csv and then attach that to the email.
00:10
Okay so we'll start really simply just by creating out a mail so let's go and make out a referral payout mail class and then inside of this referral payout let's just take a look at what we've got so referral payout and here we go okay so we've got a subject pretty straightforward I'm just going to leave that as it is we've got the content you can either use mark down in here
00:32
or just defer to a view which we'll create in a minute and then really importantly it's our attachment section which is where we're going to be generating and attaching the csv that we need to pay out to so let's just create out a view really quickly for this email we're not going to bother filling this in too much so let's make a view and we'll call this referral payout we'll
00:50
put it under an emails directory okay so let's go and fill this in emails and referral payout and let's open up that referral payout email view and in here we'll just say pay out in there that's it we'll just keep that as that for now we're not really focused on the body okay so how we are going to send this email well we need some way to test this locally you might
01:14
already have something set up but let me go ahead and show you how I set up mail pit so I've already got this installed so let's go and just run mail pit you can install this on multiple operating systems and once you run that you're going to end up with a host running here so let's go and open this up really quickly in our browser and there we go any mail that we now send from laravel is
01:34
going to land directly into here so we'll need to configure this so let's go over to emv I think I already have this set to 127.0.0.1 but you just want to make sure the port's 1.0.2.5 and you have your local host running like this okay we should be able to send an email now so let's go ahead and do this and we will send this to an admin now I'm not going to hard code this in here I'm going
01:55
to add this to our referral config really importantly so if this needs to change later it's very easy and we are just going to send over that new referral payout email and a little bit later we're going to send these records down to that so then we can generate the csv and then attach so for now let's just comment out what we've got here and we'll just make sure that this
02:19
goes ahead and runs through okay so we're going to come over to our payout endpoint that we're using to test and if we head over to mail pit sure enough that email has been sent with that body and of course we want to actually attach a document to this generate out the csv and attach a document so let's go ahead and look at that next

Episode summary

In this episode, we dive into sending out the referral payout email to an admin. We start by creating a new mail class specifically for the referral payouts, keeping things simple for now. You’ll see how to set up the subject and basic body content, and we quickly scaffold a view for the email (kept minimal for now).

Next, we get our local email testing environment up and running using Mailpit. If you’ve never used Mailpit, you’ll see how easy it is to install and configure it so all outgoing emails from our Laravel app can be viewed right in the browser.

We hook up the admin recipient to our referral config so that it’s easy to update in the future without digging through code. Then we send out a test email using our payout endpoint, and sure enough, it shows up in Mailpit!

We don’t handle CSV attachments yet—that’s coming up in the next episode. For now, this episode is all about laying the groundwork for referral payout emails and making sure we can test them locally.

Episode discussion

No comments, yet. Be the first!