How to use SMTP on Laravel

This article focuses on the usage of SMTP on Laravel. From setting up SMTP to the codes used on Laravel will be clearly explained.

Updated: 14 Dec, 21 by Elizabet J 2 Min

How to use SMTP on Laravel

Laravel is a PHP framework that has been featured today by many developers thanks to its unique features.

Set up SMTP in Laravel

Setting SMTP or sending emails in Laravel, like other infrastructure settings are done in the env file. So whether you want to use a SMTP server or SMTP host, you only need the following code in the env file. This file is located in the Laravel main folder.

In this article, we will go through using SMTP hosts.

In order to do this, you first need to create an email address on your web host and then create the following code in the env file. Enter the main folder.

The codes required to use SMTP in Laravel are as follows.


MAIL_HOST = host name of server host

MAIL_PORT = 587 

MAIL_PASSWORD = password


MAIL_DRIVER: In this section, you should specify the type of email that will be the same SMTP.

MAIL_HOST: The email address of the email will be entered in this section, which is the same as the domain name or the name of your email server.

MAIL_PORT: Enter the port server to receive email from LARAVEL side on this line.

MAIL_USERNAME: Enter the email address you created on your server or host.

MAIL_PASSWORD: Enter your email account password at Hat.

MAIL_ENCRYPTION: The type of email encryption in this section can be specified that it should be placed on tls or null.

After adding the code above, save the file and exit it.

In this way, the settings required to send email via SMTP in Laravel are completed and read for use.

Note: You will also be able to use Gmail's SMTP through the same settings.

Elizabet J

Elizabet J

One OF my major goals is getting new experiences about ICT and what’s more making progress through this field.

user monovm

Ms. Clarabelle Daniel II

2024, Jun, 24

This is a fantastic guide on setting up SMTP with Laravel! The step-by-step instructions are clear and easy to follow, making it a breeze to configure email services. Setting everything up in the env file is a straightforward approach. Looking forward to more helpful articles like this one. Great job!