1. Home
  2. Docs
  3. Ultimate Grocery App
  4. Backend Configuration
  5. Email SMTP Setup

Email SMTP Setup

In this tutorial, we will discuss how to configure our Laravel applications to send emails using your Gmail account as a Gmail SMTP server with the default Laravel SMTP configurations.

The benefits of using an SMTP server cannot be over-emphasized, with an SMTP server we can send emails from our local server. Thus, giving us the ability to test the email functionality on the local server itself. Mails sent via SMTP are not flagged as SPAM by Gmail as seen in emails sent using the PHP default mail() function.

Step 1:

Open cPanel And Open your API code. and edit .env file

Step 2:

Configure Gmail SMTP Server in Laravel Application

Laravel uses config/mail.php file for storing details used in mail sending. This file contains settings like MAIL_DRIVER, MAIL_HOST, MAIL_PORT, etc. In order to successfully send an email, we need to provide this information.

To add this required information, we need not edit this config/mail.php file, rather we would supply these details accordingly in the .env file.

Thus, open your .env file which is located in your root directory of our application and checkout for these settings:

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

Now edit the details above as follows.

In the above settings, we configured MAIL_DRIVER as SMTPMAIL_HOST for Gmail as smtp.googlemail.comMAIL_ PORT for Gmail as 465, and MAIL_ENCRYPTION method as SSL.

The MAIL_USERNAME and PASSWORD should be replaced with your Gmail Email address and Password respectively.

Since we are using Gmail SMTP, we need to change some security settings on our Google account, to give access to less secured applications.

Step 3:

Login to your Google Email Account and click on Google Account Button. This button is displayed when you click on the profile picture in your Gmail Dashboard as shown.

Once you are on the My Account Page then click on Security and scroll down to the bottom and you will find ‘Less secure app access’ settings. Click on the radio button to set it ON.

You are done!!

Was this article helpful to you? Yes No

How can we help?