Laravel 9 Ecom - Part 60: Send invoice mail using Gmail SMTP in Laravel 9 | Laravel 9 Mailer Tuts

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey guys welcome back so guys we are continuing a lot of online e-commerce Series so guys now in this video we are going to learn how to send invoice via mail okay so guys we will be using a Gmail and sending this invoice okay so guys as we have seen that when you click on view and watch you view all the invoices and then we are going to send this invoice in your Gmail account so guys I have just logged in one Gmail here and I will be sending a mail of this invoice okay so guys now let's get started so first let's create a button here guys send the invoice via email okay so guys let's go to this path admin orders and its ID so let's get back okay so let's move to this admin route and go to your order so let's move below here you see guys we are on the order controller and here is our order index and on the get method let's go to this show function let's move on this order controller let's Ctrl e and search for order controller inside admin let me close this everything so we are inside order controller at show function here is our show function and now you move to this view blade file and here is a download invoice and view invoice so say we are going to copy this and paste again until send invoice via mail okay and now guys you need to add a concatenation here and just type mail that's it so admin invoice you are going to send via mail that's and now here info let's see if and now let's see the output once good so let's create the route and set up everything for the mail so let's get back let's copy this complete URL and get back to your web.php so we are going inside the order controller itself here itself only let me paste it and let's copy this route guys Ctrl CV and just get this invoice we already have an invoice and here Order ID so we are taking quarter ID and getting this mail and you are sending here that's it let's remove this admin is a prefix so we have already defined at top so here it's admin okay so you don't need to add that yep guys and now you can start moving to here mail invoice so let's copy this and create a function inside your order controller so let's move inside the order controller and let's move below so here you see we have this function right let me copy this complete function code and paste here and let's place this add this function name done guys so you are sending mail invoice integer order ID and you are getting the order ID searching for the order and now let me remove this as simple guys so now guys let's start with sending the mail here okay let me just zoom in guys all set now open your terminal and create the mail mailer PHP audition make mail the mail name it's going to be invoice order mailable okay invoice order mailable okay hit enter so mail created successfully now let's move to our app folder let me align everything go to app mail and inside mail you'll find your invoice order mailable okay so now guys let's type here in your order controller at mail invoice function let's tell mail colon colon to function and then use a send function okay so here at 2 what you are going to tell so 2 is nothing but you are going to provide the email address so on this order variable okay you are getting the data and sending the email ID okay so right now if you see here on this order id4 here is the email so make sure you are adding the valid email address okay to receive a email okay so here I see so on this id4 here is a valid email address I have pasted which is logged in over here all set guys and now we can get back and you send this mail and then at the send function new and your mailable so what is the mailable here you find that invoice order mailable let's copy this guys Ctrl C and get back and paste here so this is your invoice order mailable and then let's send this variable dollar order you are sending inside this as simple guys done and now let's return redirect function with the message so add the message comma invoice mail has been sent to the email ID if you want you can paste it okay so let's copy this email and concatenate and send it that's it guys let me just here okay and at this redirect where are you going to redirect back it's going to on the admin forward slash I mean to say this URL okay so let's copy this get back and paste it add this number four you are going to take the order ID let's remove this just concatenate and paste it all done guys and now guys once you send this mail you'll face some errors like you have not set up or the set of the password email address everything so make sure you are setting that in your dot EnV file so let's get back to dot EnV file here you see let's move below add this mail level let me close this terminal so here is an mail setup okay so here you have to set up everything so I will tell you how to set up these things so first let's get back and here you can write a try cat statement here let's use try and catch function and you are going to push inside this try and at the catch you will redirect like something went wrong a simple guys and now when you are successful then you are going to show here and move this inside your try catch itself and inside this catch just use backslash and use exception dollar e outside and if you want to know the message you can just take and print the exception error okay and now guys make sure you are importing these classes so import this class mail so mail imported and now you have this invoice order mailable also import its class okay both are imported let me just show you so here you see the invoice and your mail perfect done guys and now coming to your mail let's move to this invoice order mailable so at there you will get this order variable let's get back to the invoice order mailable at here is a public and paste your variable dollar order and same data you are going to copy and paste in your constructed method so inside this you are sending and used dollar this of order make sure you are not adding dollar okay equal to and dollar order so you are getting the order storing inside this and then guys you are going to view the template okay so here at this view let me first send the subject also so dollar subject equals to inside double quotes your order invoice done guys which you can see this on your mail subject and you send this data variable in a subject function so what we can do here let me give Arrow and subject function and then send this variable subject all set and now guys you can go to the bleed file so at which blade you will be going I will be going on the same invoice blade okay at the same template so you can see the invoice here okay so invoice and the ID let's get back so you go to your web.php and you see that invoice and the order ID here you go to your view invoice okay that's a function let's search for that we invoice here it is and here it shows the path okay so let's copy this path guys and get back to your invoice order mailable at the build function at view method so here you paste the path okay all set and inside this file you see all the variables are in order main thing okay so this order variable only we are sending it so make sure you are also sending the exact variable what you are using in your generate invoice blade file okay so now it's all set now we can get back and everything set up so final one setup is trending that is your mail configuration so let's get back on the dot EnV file so let's go to your dot elv file okay so now guys this mail mailer is going to be SMTP and the type of mail we are going to use is Gmail Okay so smtp.gmail.com you can keep in the double quotes also and here Port it's going to be 587 because it's TLS and here you are going to give the username or email ID so I have just created one dummy account like test Funda of web ID at gmail.com okay let me keep in double quotes and the password you are going to set as the app password okay so how you are going to set up the app password let me just show you so I have written a small post guys how to generate or create a Gmail app password so you can follow these steps and create it as simple so but let me just show you a demo also so here you go click on this account and then you can get back to this thing blog and you find all that go to security and set up that password here how to set up that select an app so here at the select app on this rounded select the mail and give the custom name okay so example on select app select as mail and on select device just use my website application name okay so anything and then generate it so once you generate you see 16 characters app password okay so you can use this app password and paste in your EnV file so I'll be pasting it guys and encryption you can keep it as null itself and let me copy the username here hello paste here and then app password is going to be the same what you have provided here in the top happening okay so all set guys and now once type your skin character have password and set it okay so guys I have closed my EnV file okay so let's move this view blade and see once the button send invoice via mail and oops just remove this Target under the blank guys over here I have removed it let's get back once refresh and now let's try to send the invoice via mail done guys and now let's send invoice click on it so here you see you have got the message as in voicemail has been sent to at this email address so now guys let's go to this email address and just check okay let's go and here you see perfect so you have received that from the e-commerce your order invoice is your subject what we have set and all the data has come whatever invoice you have given perfect guys well done it's responsive also and if you require to add anything extra so you can copy this same template generate in watch template and link to your invoice order mailable here you can link with a separate template and add your extra details that means extra detail means like your social media links and all you can add on okay so this is the extra works you can continue so guys we have successfully learned how to send an invoice via Gmail okay so let's in this video that's it and let's continue next video with the new topics so thank you for watching this video guys please subscribe like and share
Info
Channel: Funda Of Web IT
Views: 5,731
Rating: undefined out of 5
Keywords: fundaofwebit, Send invoice mail using Gmail SMTP in Laravel, how to send email in laravel, laravel 9 send email using gmail, send mail using gmail in laravel 9, how to send mail in laravel 9 tutorial, how to send email in laravel 9, how to send invoice mail in laravel, how to send data as mail in laravel using gmail, laravel 9 mailer tutorial, laravel 9 ecommerce send email via gmail, gmail smtp serve in laravel
Id: Yby3_6DJRfY
Channel Id: undefined
Length: 14min 36sec (876 seconds)
Published: Tue Oct 18 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.