Laravel

How to send email via gmail smtp in laravel

How to send email via gmail smtp in laravel

How to send email via smtp in laravel

How to send email via any smtp in laravel

Here we will learn how to send mail via GMAIL smtp in laravel. Send email via gmail smtp. First if all create a new laravel project from command if you have not set up the laravel project. If you have project then skip this.

Step 1: Open the project root folder which we created now and open .env file and give the credentials for it:

Step 2: Now, Let’s create a mail class in Laravel as follows. This class know as Generating Mailables class.

After Mail successfully created, you will find the file path: app/Mail/UserMail:

Step 3: Now, open the Mailable file at app/Mail/UserMail and paste the below code as follows: 

Step 4: Now, create a email template design, file named with usermail.blade.php, in this path of resourse/views/emails/usermail.blade.php.

Note — You change this file as per your requirement.

Step 5: Now, create a file controller named UserController with the following command:

Step 6: go to your controller folder, path: app/Http/Controllers/UserController and Change code like bellow:

Step 7: Make a route for calling the contact form and submitting the form as follows:

Step 8: Now, Go to your gmail.com and Login in it, and then click on Mail icon & Choose  Account. 

Once you are in dashboard, click on Security and scroll to bottom and TURN ON “Less secure app access”.

Note — IfLess secure app access” not work. Please generate app password in setting and use this password in .ENV file password field.

Thanks for reading.

Visited 14 times, 1 visit(s) today

Leave a Reply

Your email address will not be published. Required fields are marked *