Laravel 9 Send Email using Gmail SMTP Server 2022 Latest

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] in last year if you want to send gmail out via your own application you have to turn on the lessexual app in your google account but still now today google no longer support and shut it down this feature i think you may face the problem how to send gmail via your laravel app or other app and i will show you how to configure gmail to send out so today i'm going to show you how to send a gmail from your lara app and smtp configuration now in this visual studio code i have installed laravel 9 and and the left side here is the project structure list okay now let's launch the terminal we're going to generate a malleable file that going to implement emails to send out so let's type the command and i'm going to name this file as the mail notify okay the file is created successfully and the file is located in this directory and now in this file you can see is the class that extend from the mailable class so now i'm going to define an array to store the data which we will paste it from the data from the controller via the constructor then i'm going to set the data where this constructor okay this method is important to send the gmail out so we're going to implement it in this function and i'm going to remove to this thing out so let's call the method where you want to send it from which is uh it's not a real one you can put whatever and then the second parameter we are going to name it as descender the sender for example this is my channel name and then uh with this chaining method we're gonna call a subject function to pass the email subject so this i will set that with the data from the controller with the dynamic value and then we going to paste to the html view which is located in emails directory but we are not graded yet we going to start to create a black file which is located in the email folder so let's grab that folder and i'm going to name it and then create a new file for the blade and display file will show in the body email you can design any style whatever you want it will show in a gmail in an email body for this example and we show for simple no design anything and show data which is pasted from the controller file okay now let's create a controller with this command addition and i'm going to call this a controller file as the mail controller and the controller file we generate in controller data free and i'm going to implement it with our methods to send data to the mailbox so i'm going to set this sample data in the controller with a subject and the body and then i'm going to use a try catch exception to cut the failed email send if there is any and i'm going to change this to the exception class if we need to import use a mail and the mailbox class that we have a grade in at the first place okay let's call this main class to send out and this uh the receiver email that i'm going to use this email for testing and receive the email message we call send function and paste the mailbox instance in the data with the data in the constructor and if there is no error occur with this line we're going to return respawn message.json format and then i'm going to copy this return and paste it in the catch absorption to return if this error happened now we are going to add this route list with this controller and the route is located in route web.php and i'm going to add the new route link with the gap method and the second parameter is array then we paste the controller class and we add this namespace with the class name and then the function name which is index and i think that we better put the namespace and the class name on the top so let's copy this and paste it in here and now we almost completed the important is to configuration the smtp to send out with a gmail account this as my configuration make sure that port host driver name and encryption are the same as me but for the username is your sender gmail account and the password is the 16 characters generated from the ad password in your gmail which is not your gmail account that you usually log in you can read the article that which is a really short one how to set up a password i have wrote very simple and if you place the link below before you send out make sure you have turn on your antivirus or firewall just in case you got an error ssl exception and i already disabled my antivirus so now let's run the laravel server by this following command i'm going to navigate to the links route send email directly okay maybe i'm added the incorrect namespace here which does not exist so let's go to route okay i'm going to copy namespace from the controller there then i'm going to paste it back now i think no more error occur okay so let's go back to the browser i'm going to refresh this and you can see this loading a bit longer because it's going to send out okay we can see that messages mean that we have no error to send out so i'm going to open up my mailbox and there is a new email in my inbox message if i open to read you can see it's very simple text with the title x3 elements and the body tag which is replaced from the controller file all right you can find this source code in the link below i have wrote this as well please go and check it in campbelltutorial.com which um daily post lateral article and other tutorial as well and i hope this tutorial helped you to send gmail out in the laravel app please consider subscribe and like my video if you think this helpful and i wish you in the next video thanks [Music]
Info
Channel: Cambo Tutorial
Views: 29,809
Rating: undefined out of 5
Keywords: Cambo Tutorial, laravel tutorial, laravel 9 tutorial, laravel email, laravel send mail, laravel send email, laravel 9 send gmail, gmail larvavel, send email laravel, less secure laravel send email smtp, laravel send email smtp, laravel gmail, laravel 8 send mail from localhost, laravel send mail without smtp, laravel 8 send email example, less secure app, less secure app access gmail not showing, less secure apps & your google account, less secure app access gmail
Id: L5LAqIABGZE
Channel Id: undefined
Length: 8min 10sec (490 seconds)
Published: Sun Aug 14 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.