Laravel 9 Send Mail using Gmail SMTP Server
https://www.itsolutionstuff.com/post/laravel-9-send-mail-using-gmail-smtp-serverexample.html
Last updated
https://www.itsolutionstuff.com/post/laravel-9-send-mail-using-gmail-smtp-serverexample.html
Last updated
Today, I will let you know an example of laravel 9 send mail using gmail smtp. I explained simply about laravel 9 sending mail google gmail. this example will help you laravel 9 send email using google gmail. you will learn gmail smtp send email in laravel 9. you will do the following things for how to send email using gmail in laravel 9.
Laravel 9 provides an inbuilt mail configuration for sending emails. you can use several drivers for sending email in laravel 9. you can use smtp, Mailgun, Postmark, Amazon SES, and send email. here in this example we will use google gmail mailer driver for sending email.
In this tutorial, I will give you step by step instructions to send emails in laravel 9. you can create blade file design and also with dynamic information for mail layout. so let's see step by step guide and send an email to your requirement.
Step 1: Install Laravel 9
This step is not required; however, if you have not created the laravel app, then you may go ahead and execute the below command:
Step 2: Make Configuration
In first step, you have to add send mail configuration with mail driver as gmail server, mail host, mail port, mail username, mail password so laravel 9 will use those sender details on email. So you can simply add as like following. So you can simply add as like following.
.env
Make sure you have to enable google security setting form your gmail. go to Google account and click on ‘Account’. Once you are on the ‘Account’ page, click on ‘Security’. Scroll down to the bottom and you will find ‘Less secure app access’ settings. Set as ON.
Read Also: Laravel Mailchimp api integration from scratch with example
Step 3: Create Mail Class
In this step we will create mail class DemoMail for email sending. Here we will write code for which view will call and object of user. So let's run bellow command.
now, let's update code on DemoMail.php file as bellow:
app/Mail/DemoMail.php
Step 4: Create Controller
In this step, we will create MailController with index() method where we write code for sending mail to given email address. so first let's create controller by following command and update code on it.
Now, update code on MailController file.
app/Http/Controllers/MailController.php
Step 5: Create Routes
In this step, we need to create routes for list of sending email. so open your "routes/web.php" file and add following route.
routes/web.php
Step 6: Create Blade View
In this step, we will create blade view file and write email that we want to send. now we just write some dummy text. create bellow files on "emails" folder.
resources/views/emails/demoMail.blade.php
Run Laravel App:
All the required steps have been done, now you have to type the given below command and hit enter to run the Laravel app:
Now, Go to your web browser, type the given URL and view the app output:
Read Also: Laravel 9 Markdown | Laravel 9 Send Email using Markdown Mailables
Output:
I hope it can help you...