How to to send mail using gmail in Laravel?

How to to send mail using gmail in Laravel?

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Configuring Gmail SMTP in Laravel: Beyond the Basics

Setting up email delivery for a local development environment often trips developers up due to specific security requirements imposed by Google, rather than misconfigurations within the framework itself. The source material provided shows a standard configuration attempt using config/mail.php and .env variables, but it fails immediately with an authentication error. This happens because modern Gmail accounts have deprecated support for less secure applications and plain text passwords, rendering a straightforward SMTP setup impossible without additional steps.

The initial hurdle lies in the encryption setting found in the configuration file. The provided snippet sets 'encryption' => env('MAIL_ENCRYPTION', 'tls'), while the .env file overrides this to null. When using Gmail's SMTP server (smtp.gmail.com) on port 587, you must explicitly use TLS encryption. Setting it to null disables the secure handshake required by Google, causing the connection to be rejected before any authentication attempt is made. The correct approach is to ensure the .env file retains MAIL_ENCRYPTION=tls.

Beyond configuration, the most common reason for failure is the method of authentication. You cannot simply enter your standard Gmail account password into the MAIL_PASSWORD field. Google requires you to generate an "App Password" specifically for third-party applications like Laravel. To obtain this:

  1. Go to your Google Account security settings.
  2. Navigate to 2-Step Verification and ensure it is enabled.
  3. Access App passwords under the 2-Step Verification section.
  4. Select "Mail" and "Other (Custom name)" as the app, then generate a unique password.

This generated string must replace the password value in your .env file. If you attempt to use your regular login credentials here, the SMTP server will reject the login, resulting in the error seen in the source image.

Another critical detail involves the "pretend" mode. In the local development context, it is often preferable to set 'pretend' => true in config/mail.php. When enabled, Laravel does not actually send emails over the network; instead, it dumps the message content into your application logs (usually storage/logs/laravel.log). This allows you to verify that the configuration is correct and the email was constructed properly without needing to worry about Gmail's strict security filters or hitting daily sending limits.

If you need to switch from TLS to SSL for specific legacy reasons, note that Gmail does not support SSL on port 465 in the same way other providers do; you must stick with port 587 and TLS. Furthermore, if your Gmail account has "Less secure app access" enabled (a deprecated feature), you might bypass the App Password requirement, but this is strongly discouraged as it exposes your primary credentials to potential interception.

Finally, ensure that the from address listed in your configuration matches the email address used for authentication. Mismatched sender and login addresses can sometimes trigger spam filters or cause Gmail to block the connection entirely. By aligning the encryption protocol, using App Passwords, and leveraging the pretend mode, you can bypass the immediate roadblocks shown in the source material and achieve reliable local email delivery.

Our network