 okay hello part two right so mine is going to be a little bit more focused it's just one one area of Laravel all right it's going to be about mailables and sending emails and whatnot okay so that's my name and that's my surname all right just mix them up okay right so the obligatory about me right I work at abscess abscess all right we do this if you've gone to um if you've gone to uh i'm supposed to see the rehearsal and my notes am i using am i using keynote problem sorry amateur command f1 come on come on f that f1 come on yeah sorry newbie obvious really oh i got a there so i need to go to uh don't mirror sorry oh yeah yep yep yep sorry sorry sorry yeah well if there's one way to uh you know kind of uh prove that i'm okay all right just play right here we go all right sorry i have to edit that part out okay yeah all right so um the company i'm working so it's like free advertising thank you uh uh we use an ipad for the porno cell machine the menu so you've eaten at places like the old street buckle day or if you've gone to timber right yeah you may have used our product there so we will choose uh produce kiosk for uh i think it's suit us um um what was that leo fun leo fun yeah the the famous um i'm roasted duck thing right yeah so so that's that's uh what we do so um yeah so you can tell for the hair color i've been around for a while so i wrote my first program way hell better probably before you were born or something like that so yeah i know i'll try to look at it positive and i was using basic i'm not gonna ask hansa for who those who know this because it's like you know so but but most significantly in 2021 i discovered something called php all right and that that story of how i discovered this it's going to be over coffee or something like this is a really long story because it's very interesting but it's like one of those things that goes you know the light bulb just goes up it's like i can make web talk to databases you know it's like oh you know all right but so so within seven days i hooked up php and i was crazy back then i hooked it up with microsoft sql and i was extracting reports for gd at works so it was like peddling peddling reports to my accounts manager like drug sex so so extract reports for for the erp system on web back when internet was liars dn64 okay that kind of that kind of time so yeah all right so yeah i've been having fun ever since then it's like crazy all right right so um so this is essentially going to be talking about you know larival and emails but a little bit of background is like a web applications and email what's that over here right um i think you'll be hard pressed to find any application right now online web application that doesn't need to send email right you sign up something you're going to get a verification email you book something you're going to get confirmation email whatnot right so during the sign-up process um when you reset your password you're going to get a nice token you can click and go to and reset your password confirmations of your bookings and whatnot and spam right okay so um that's web applications in email so for php um how do we send emails right all right this one i'm going to ask for a hands up i'll use this before yeah that that that that my diverse condolences right you know how you know challenging this is to use this right when it doesn't work if we are wondering is it my code or isn't my signed mail or is there something else right and this is not going to be very good because you're trying to send from your laptop it's going to try to send directly through an mta and and you won't work if you're running on windows because you don't have an mta right and and and you have no ptr reverse ptr you know spf records and whatnot and then it's going to go to spam if he even goes through at all right so later on then some nice guys gave us this right a nice library as probably some of you still using this right come on go on go on admit it yeah okay i know all right so in our favorite framework all right we have this okay it makes our life a lot easier okay right so larival and emails so larival gives us a nice api that's on top of the swift mailer library and that guy gives us a lot of ways to send emails right and all you have to do that is just configure this in your config mail put in the right driver here right so you can use smtp mailgun spark post amazon right good old php mail and even send mail if you have it around right okay so sorry where sorry that's what you got for now all right maybe there'll be new ones okay so it's on top of the swift mailer library right but you don't have to use it directly okay you can use the mailables class so you may not have used this maybe you know uh truth be told i just discovered and really use this for real or just just two weeks ago so i figured why not talk about it all right so in larival every type of email you send is actually a mailable class so if you want to send a welcome email you just create a class to handle that type of email okay and if you want to reset password email just create a mailable for reset password all right so it's just one class one type of email all right and you create them using the artisan command all right and they will be stored in the app mail folder so the artisan command also creates a folder for you if it doesn't exist all right real easy all right so that's the larival side of it right now there's another component of my presentation is actually mail trap dot i o okay this is like where was this all my life mail trap it's an online service i stole this from their website don't tell them okay now during development all right um when we test emails we end up typing fake email addresses like email email dot com or you know nobody at email dot com or somebody at company dot com that's not gonna go anywhere all right and um we also like to be a test with real ish email addresses right but we type real addresses we're gonna end up spamming people so we end up using our own email addresses and then we spam ourselves and we flood our own inbox we follow a lot of tests until you miss the one that comes from your boss that says come see me right yeah so there you go right so so you clutter up your inbox it's not nice so mail trap i o is actually an online platform all right a service that provides you a fake smtp server so it's really smtp but as his name says mail trap every mail address that you send to mail trap gets trapped there so i could just send with donald trump at whitehouse.gov it gets trapped here so poor donald doesn't get my words of wisdom for him you know how to run the country etc right okay so mail trap traps everything so we're gonna get to looking at the interface a bit later all right so yep because it's an smtp server when you're ready to go to production all you have to do is just replace your smtp server host name put in the username and password you're good to go that's all you need to do just configure and it works and you've already tested your classes and everything so you really know how your email looks like okay all right so um right so the next half of my presentation is actually a hands-on demo right so you're gonna see the actual process of how to how to how to produce this so a quick brief run through of what's going to happen during the demonstration is um we're going to sign up my mail trap or rather login because i've already signed up right mail trap i o okay we're going to configure the smtp credentials so that i can send the email to uh through mail trap okay then we're going to create a mailable class in laravel and we're going to create a view now we represent the contents of an email using views so you can just use blade that you've always used right right very easy and then um just to test if it works quick and dirty way do a test route in your route file right and just see if it works and then close your fingers right if all of that works then you start linking it to your application itself and in this case because it's a welcome email i'm just going to do it i'm going to link it all into the registration controller so once someone registers on my site they're gonna get an email yeah okay and then if we have the time then i'm gonna do something that melvin has already mentioned very eloquently later is that don't make the user wait because email would be like talking to an api it's going to be slow as well all right so we should be using queues to do these kind of things yeah all right so let's do this yeah okay uh yes mail no no no it's a generic SMTP yeah yeah yeah uh just a couple of so not this one yeah right uh yeah in a while you're gonna see i'm gonna switch to mirror first uh the interface is pretty pretty pretty dang cool actually okay how's the phone size okay let me check let me get all the phone sizes checked out first right big enough okay let's get the window down a bit yeah can read that right okay sublime actually that's my default phone size this kind of ice you know okay let's got that got that and this guy i don't really need this but just for the sake of argument no i won't truncate this okay go away bye bye sorry sorry sorry i'm very not organized today is that big enough i think so okay okay here we go right this is a cleaning solution a lot of go okay uh but you notice on the top right corner sorry one of my just yeah not here am i on the right branch yes i am okay right you know it's on the top right i have the login and register no magic here actually just run php out this one make all all right it's going to create all of this for you right run the migration create the user table if you don't know how to do this and you're really curious look for this guy at the end of the thing all right okay so i've got registration set up it's a cleaner installation of laravel so the login works and the registration works right now uh my database is clean so i've got no users yet so let's just register one guy so somebody so john smith john at company.com blah blah blah voilà nothing right so i've got a user now okay all right so i've got one user now the row id is one okay right here we go uh right so you can find the smelvin also pointed out the one of the really good resources honestly the laravel's official documentation anyway right so i forgot to set up my wifi down here okay that should work i just don't do anything sorry it should still work all right first step we're going to create a mailable class okay so i've got a code here cd presentation okay i'm in here i've got a code all right i've been playing with this so i don't have a mail folder yet all right so phb already signed all right you guys see all the available commands right so it's make mail right phb already signed make mail and we're just going to make the welcome class to send a welcome email all right mail creative successfully you'll see a new folder called mail and we'll have the welcome class here so this is what a plain old empty mailable looks like is that too big still readable yeah okay right so most of the magic happens actually in the build function the build method over here all right now you can specify the view the tool the subject the from and all these kind of things inside the build method down here um the documentation is a little bit sparse on that honestly but you actually would be better served to go to the api documentation and find the illuminate mail mailable class and that's what you're going to see that you can actually specify all of these properties with all of these methods so you can actually queue it later build view priority from to ccb cc everything down here so in addition to the documentation so it should really refer to the api uh documentation frequently when you're doing this okay all right so this is mailable class empty and um right so we're going to send an email to a user so we'll need to have this to be able to read users also i'm just going to use the default user model right that lives here is already created all right and in the i need to declare a public property to hold this and then type in that into the constructor okay and then once it's constructed this user equals to user right everybody knows this right okay so over to the yep give me a second so the thing is that once you make this public this user will be automatically be available inside the view file you don't have to do anything else but if you want you can actually make it protected and then you can transpose your data a little bit before you inject it over to the the view itself but setting it public is a quick and dirty way all right it's more than four ways to do something in Laravel okay so now um we're going to create a view file for for this so it's a resource uh views uh new folder emails and then welcome dot blade dot php all right that's going to be the body of the the email i'm going to change this to the view file right so emails welcome i can do this as well mouse emails welcome all right so let's gonna bring in the blade file down here so let's very quickly punched out punch out a email body so welcome and we know that the um the user table has name and email right that's all i need to to use uh for this purpose so i'm just going to do a you know hello um the user's name right this blade right so i'm just stick some lorem store some lorem in here yay okay that's fine okay yeah right that's this okay thanks okay what am i doing okay right right so i've got nearly everything set up i've got a class i've got a view right i've got the object okay and uh we're going to do a quick you know just a quick test route you know there's something to punch out really quickly so we're going to do literally just a you know simple url that essentially once i hit um test just right closure here okay and so um the route file so i'm not going to namespace these things i'm just directly type uh straight up so it's like um yeah user equals those those those uh pros among you it's gonna cringe at all the things i'm using down here but yeah well user like that fine number one okay done quick and dirty right okay yeah yeah yeah i know laugh it up mail to user email address right and send all right the new mailable class that we have right welcome class and then you inject the object inside follow so far or i've completely lost you all right so as long as i hit my test url i'm going to send an email but i'm missing one piece i haven't gone to mail trap yet right okay so we're going to go to mail trap sign up you can watch the video on how it works and whatnot so this this screen is a little bit right so i've i've already have a account so i log in oh shoot i need internet um where okay somebody read to me wait wait wait wait which one is it guest property guru okay and and there's one pg ur us one exclamation who touch type is yay come on come on work yay all right reload come on oh go away right so when you sign up at mail trap there are different tiers you know the free and then pay money pay money pay more money right right so this is the i'm i'm you know a poor struggling programmer so free tier right you get one inbox okay 50 the messages more than enough for for testing so once you get into inbox first thing you're going to do is wow gives you the settings settings for ruby setting for jango dad answers your question right hey michael yeah so cake you know configure this way right lara vow configure this way actually it's even easier than this but you know they give you all the integrations down here how to set it up it's like it's like real easy let me get rid of all of this first i've been playing with this all so this is my empty inbox you've got the the the help down here funny thing is reviews on an iPad this all disappears so that's half an hour of my life i'm not getting back all right so um you will see here your s ntp credentials basically set your host to hear port numbers to this this all that username password and then your encryption tls is optional right we only need this and that because in the default installation of lara vow it actually is already set up it's actually null and then null down here and then no encryption but it actually is set up as mail trap 2525 already so we don't have to do anything down here so let's pretend i have i just i just did this right okay so my installation lara vow is ready to talk to mail trap every email i send out is going to go to mail trap right so what do i do now yep okay hard stopping woman here we go i send an email right so the test route loads a user sends an email right please work it's gonna take three four five done right no output let's see what happens aha there we go uh why do i get two hang on hang on hang on did i visit it twice did i i think i may have had hit enter twice just now i don't know let's let's wipe it let's do it one more time it shouldn't work twice this works too well there's no bcc right come on there we go yes just one okay right you can actually see the email immediately here well it's immediately as your queue runs right so you see the htm email right that we got the name correct yeah we've got my lauren ipson correct down here all right we've got john at company dot com this is all the things i specified but why i wonder if they have a from i didn't specify this i didn't specify the subject line all right that comes on the class name okay and this if you don't specify it it's going to come from your configuration just come from from default there we go if you don't specify it's going to lift it from the configuration so you can put it in env all right or else take it from here which means if you want a global from address all right then you don't want to you know literally all over your classes the entire level installation you say from more right and the name of where you say from so you can you can put your global addresses over here okay got it so that's that's that's how it's but we don't want magic right so we're gonna show you how to really explicitly specify everything so we're going to do that inside the the mailable class itself and yep so i've got the view here so far right i specified the tool from my route which is going to be your controller right so now i'm going to explicitly do it also it's to this user because i've already injected it you know here here i've got it here right so this users email address right and i can actually put his name because the the the two method takes two parameters one is actually email address and the other one is just a string that that's that's going to give you a nicer looking header right i'm going to specify explicitly the subject line as well so have welcome to example.com and i'm going to specify from as well to overwrite the the global setting so from members at example.com and specify a string name as well so it's example.com members okay and i'm going to just do a blind copy to support at example.com so they know okay i've got a new sign up i can support them yada yada yada so i don't need this okay so all right we've got all this in place right so let's go round two all right let's see what happens right go uh and bink something really i've done this like four times and anyway right so you see my better looking subject line i've got the the from specify properly now right this still works but right now i actually have his name showing up as well all right so the content is still the same all right now so so we've got that working all right and you notice a couple of tabs down here which is really helpful because if you do it in your thunderbird and what you're going to have to write your view source and all this just peek around and see what's happening but you can actually see the HTML source just like that you know so you see what's going on and you didn't have a raw view file as a whoop you know the message headers all of this you have you have this all right okay i'm going to leave the other goodies for later you know just feed you bit by bit right uh let's let's ramp it up a little bit right this is just all text it's so boring let's get some pictures into it right okay so let's get a picture i've got uh i stole another image so it's over here all right public images welcome so let's stick into the view file right standard html so i'm going to use the nice larval helper for the asset all right images welcome jpg and let's do this again come on give me one one okay i may i may have left something in there but let's see what so okay here we go so now i have a horribly large image but yes it's like screaming welcome all right so this is actually a link right because i used the standard asset which is going to be just a web page right so it's an asset link so this is a link which then there are good good good lead in because it's going to go to the next part of it embedding right sorry is the bcc coming through is that your second remark bcc i oh yeah yeah yes sorry yep there's this specified bcc so yeah so this is the one that goes to bcc support so this one should be just to john ta-da thank you yeah yeah yeah yeah but it did happen before i put the bcc that was because you had the request load in the browser today with the wi-fi and it's triggered okay there you go mystery soft i can sleep tonight now thank you right so the source right right so so yeah this is a just a normal load right so so here's another option some of us may not have used it before it's got embedding an actual image right this means that anyone opening the email is going to hit your web server just to look this right you may want this for marketing tracking you actually may not want this if you just want it to be embedded right but if you want to do it by hand gonna have like base 64 encode this thing and then create a cid and like all of it's never mind our favorite framework does it very easily right okay so let's embed this right same image but we're going to embed this right so we're going to do a different way and what's going to be different is this essentially you need to pass in the message object rather than message property this is a magic property that it comes into a view of any view that's loaded from a mailable got it it's a magic property variable right so you will have this all right refer you to your documentation for this but the message property is going to have a message sorry embed something right and this one you can't use as said because you're not loading loading it from the web you're loading it from the file path itself all right so it's in my public right any geniuses tell me what's the nice way to give me the public path i just give you the answer actually public path but here's the thing i remember put the slash public half doesn't give you the final slash okay images welcome that's it okay i don't need this okay looks right okay let's see if i embarrass myself again okay let's drop all of these bye bye okay let's refresh and i'm delivering making you wait so you really hate waiting then it's gonna nicely into the queuing thing right so where is it there is coming there we go so it is in there and it's a bit slower why because it's now a cid right it's a content id thing but where on earth is it here you go it's a raw so you have the cid down here wait wait wait wait wait wait wait not not not the guy that knocks on your door and say that you know you stole something not the cid but you know content id base 64 encoded that's my image okay good or bad you know it's up to depends on your requirements so you notice that once i'm embedded is 61k i shouldn't have deleted those but before i did you know before i embedded it it's only one k because it's just text it's just HTML nothing right but once you embed you you have a larger email but whatever works for you depends on your needs okay so just show you two options right okay so that's embedding so now we've got all of this working right so let's stop using the test row and actually link it up to the registration so if the size is bigger what's the advantage of using the embedding anybody the image is only available if you don't need to rely on the connection by good server or something like that so now i think about giving presentation is the room full of tech people is sometimes you don't know the answer just go okay all right here we go right let's make this work okay let's make this work no more test route okay i'll go all the way to the registration one flow i need to get out of here i'm not john anymore want to register okay right the like i said i was using the default authentication login registration thing that comes with Laravel right so that that lives inside the register controller all right that lives in here okay i didn't write this Laravel wrote this right everything happens in the last one to create method all right it's just literally just creates a user and then returns it right so we don't want to have it return to at least so i'm just gonna just steal this over to here put it into a variable user is whoever was just registered all right now i'm just literally just gonna go to my come on yeah no no no no no here yeah so i'm gonna steal this actually no sorry did i miss a step actually i don't mean no i'm not going to that did that's melvin's world so i'm just a little bit simpler i'm a simple guy yeah yeah i'm just gonna copy this all right i'm gonna stick it into the controller down here all right yes yeah it's quick and dirty one at a time one step at a time i just i just got out from writing this no come on i don't know nope nope here come on yeah right yeah we we we thank guys obviously like to give good labels to doing actually nothing much it's just big words progressive enhancement continuous integration yeah and then we give a nicer sorry okay right so now i'm in a in a proper controller i can actually just start bringing in the the namespace stuff right so use i keep telling you right bring in the facade all right and i'm gonna i keep doing this all right i'm gonna bring in the mailable itself okay this is making michael and melvin fall asleep all right so now once i brought that in i don't need this and i don't need this as well in fact i don't need this because i've already specified two here right i specified two here so i don't even need that anymore so we just just like mail send welcome throw a user in there magic happens all right so once i create a user i'll send and mail and then i have to return user all right because i hijacked it okay so let's do jane dole now okay jane at company dot com da da okay here we go so jane's registering jane is losing hope jane is getting bored and jane gets logged in and jane gets an email there we go hello jane it works jane though it works and better slow yeah i know ha it works okay so everybody sick of waiting by now right okay good that was my whole point actually really and that css style hey let's throw it to the floor again i never went there yet so as far as styling your emails yep it's just images right now that's as far as yeah that's as far as the presentation goes you know first we try to figure it out if we can't do it we make a ton of excuses thanks oh he said a bad word oh no right okay where was that geez come on right let's go cues right right i'm not going to go into the actual setup of a qr is going to be here all night right so i'm just going to assume that it works i've got redis running i've got redis on my laptop i hope it's still running i'm going to change my q driver to redis so i'm just gonna literally just make redis handle my q okay so all i have to do is to make it listen please work okay so now my uh rd son is basically just listening for the anything that comes into the queue it's going to handle pick it up and and do it for me right so how do you change from sending an email inline or rather synchronously to queuing it for later just change this to don't you love laura well come on all right so that's what provided it works this is the most scary part of it you see you know why why it's so scary okay yeah you know two hours supervisor they realize yeah don't put the sqs in there hands up if you know what i'm talking about right tom right tom jones hey all right tom at example dot com all right yeah i know i have no imagination instantly i mean all right no waiting well at least the user doesn't wait but you know where's my mail where's my mail come on come on what the user is not waiting right all of you are waiting the user isn't waiting right that's a good thing right programmers can wait you know so you can you know check your facebook play a game come on work come on yeah that's come on drama right so tom jones got an email right right right right right so stick it to a queue right if the planets are aligned the queue will work like like like now and then the user doesn't have to wait at all so that's how simple it is okay all right so i think i've got you all so excited i'm just gonna throw in the little the last bit the bonus bit right the bonus bit right remember the last few tabs i didn't go right so we have the source we have the raw of the email right gives you an analysis whoo right spam score how spammy is your email it actually analyzes for you and it gives you all the rule names that's from like spam assassin all right zero score good positive very bad right so no relays okay i put in an image that has too few words so pretty spammy 1.8 all right html message html only no text ah bad 1.1 right so no text uh then i didn't create a text alternative of it right so how do we do this all right here we go we're gonna need a second view file everything that you see in laribor it's going to be a view file so we've got this right there's the html reach text version let's create another one right resource views emails uh welcome plain plain plain blade dot php i'm missing one so i'm gonna copy this all right i didn't copy all of it just copy this no images too bad all right we got that stick in here yep get rid of that and whoo whoo whoo that that that that that done right and no images let's do a few lines on here just just for fun okay text right i've got a view file and how to make it work right to view right view text and your plain text view file plain plain plain that's it that's all you need to do okay so let's register fred come on fred where are you register fred fred nope no waiting and you wait here come on please work and i've got time for a drink this will work this will work have patience so for this one you'll just want this command well on the laptop yeah but not on server you're not gonna do this right supervisor as what melvin said also right set up supervisor on a lander's machine it's gonna kick start in fact you can specify like eight threads running at the same time so you can actually process eight queues at the same date go through already okay that's not good something something broke okay let's see what happens down here test error there we go welcome plain dot not found welcome plain email email sir thank you there we go geez yeah so i need a new name arena our names george thank you okay and go what is about george george company i need george here no george okay all right come on hey fred came in what i do i fixed that the queue fixed itself i don't know something just laura that was so good it actually fixes itself yeah you crashed and i went back in time i fixed it all right it was a crash it was returned back to the queue right it was picked up by another track yeah okay yeah i think so it makes sense you know right so now i have a text version that i you know george got his text version and let's look at the analysis what it was what 1.8 just now no it was 2. something so i lost the 1.1 now it's like hey hey okay 1.8 it's all good don't worry so it's like you can at least you have a good informational you know a guide down here how to make yourself really not so spammy and get past it all right so nice platform free right until you need more power and it gives you a know all of this analysis stuff all right um perfect marriage for for for developers like like us okay so that's uh yeah essentially all of uh all i've got for you tonight okay so yep so i've got here we go so i've got the entire code base over in github so you can scan that copy that whatever so i've actually broken up every stage as a separate branch yeah just read the readme.md down there okay all right thank you do you have any questions or something i'm just going to bounce it back to them yeah uh so have you tried the uh um uh sweet mellow no not directly oh okay i just have to compare between this land uh mellow and uh sweet mellow oh it's still good one it's going to still use sweet mellow actually at the back you know yeah so you specify the the driver like the wrapper of the yes okay yes so it's still like the where is the wrapper of the simply need to come right right that's why just like was talking about it's actually on top of sweet mellow which then provides you all of those different drivers right so so so the environment where where i put in the mail trap username and password so when you're ready to go production put in google you know and username password and it's going to use gmail and it's going to go out all right at least you know that your application is the one that works if any problem it's going to be a network issue or an smtp issue or some other issue that's not here but you don't have to go fudge around with a sandmail and all of this while while in your development phase you know it's very disruptive yeah okay thank you thank you oh it was fun all right that's it um