Use Gmail service to send emails from Laravel

Author
By Darío Rivera
Posted On in Laravel

A few days ago I had quite a few problems with the cpanel email sending service. If the service wasn't too slow, then it failed as I was able to verify from cpanel's mail track. Because of this, I was looking for several alternatives and did testing from my application, and in the end, I decided to stick with Gmail. In this post, you will see how I did it.

Creating an application password

Step 1

The first thing you should do is log in to your Gmail account and click on your photo icon in the upper right corner. In the context menu, you must click on Manage your Google Account.

Step 2

Once on your account page, in the left panel, you must go to Security and activate 2-Step Verification. Follow the steps so Google can send you a code with which you can activate double-factor authentication.

Step 3

Once you have completed the previous step, you can go back to the Security page and select the App passwords option. You will see a list of some devices, and at the end, you will see a form with two selectable options. You must select Mail in the first case and Other (Custom name) in the second case. You must enter a reference name, and when you click on generate, the password for your application will appear.

Warning: As you will see in the explanatory text, this password will give full access to your Google account. Under no circumstances should you share this code with anyone or send it through insecure means.

Service configuration

Once you have obtained your application key, you only need to perform the following configuration in Laravel.

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail@gmail.com
MAIL_PASSWORD=yourapikey
MAIL_ENCRYPTION=tls

Personally, I believe that this is one of the best email sending services since it allows you to have a mail server with your own Gmail account at no cost. Until next time!.


Acerca de Darío Rivera

Author

Application Architect at Elentra Corp . Quality developer and passionate learner with 10+ years of experience in web technologies. Creator of EasyHttp , an standard way to consume HTTP Clients.

LinkedIn Twitter Instagram

Sólo aquellos que han alcanzado el éxito saben que siempre estuvo a un paso del momento en que pensaron renunciar.