In this post, I will show you step by step how to send email using a Gmail account in laravel 12 application.
Laravel 12 provides an inbuilt mail configuration for sending emails. You can use several drivers for sending emails in laravel 12. 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.
How to send email using a Gmail account in laravel 12
Install Laravel 12
This step is not required; however, if you have not created the Laravel app, then you may go ahead and execute the below command:
laravel new example-app
Step 2: Make Configuration
In the second step, you have to add the mail configuration. Set the mail driver as “gmail”, the mail host, mail port, mail username, and mail password. Laravel 12 will use these sender details for emails. You can simply add them as follows:
.env
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=mygoogle@gmail.com
MAIL_PASSWORD=rrnnucvnqlbsl
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=mygoogle@gmail.com
MAIL_FROM_NAME="${APP_NAME}"
Make sure you have to enable Google security setting from 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 it as ON. Read More from DevScriptSchool
Top comments (0)