Home > Backend Development > PHP Tutorial > How to Configure Gmail for Email Sending in Laravel Applications?

How to Configure Gmail for Email Sending in Laravel Applications?

Patricia Arquette
Release: 2024-12-11 05:03:13
Original
929 people have browsed it

How to Configure Gmail for Email Sending in Laravel Applications?

How to Send Emails Using Gmail in Laravel: A Comprehensive Guide

In this tutorial, we will guide you through the process of sending emails using Gmail in your Laravel application.

Configuration

Begin by editing your config/mail.php file and ensuring the following settings are correct:

  • MAIL_DRIVER: smtp
  • MAIL_HOST: smtp.gmail.com
  • MAIL_PORT: 587
  • MAIL_USERNAME: Your Gmail address
  • MAIL_PASSWORD: A generated App Password (see below)
  • MAIL_ENCRYPTION: tls

App Password

To use your Gmail account for sending emails in Laravel, you must enable Two-Step Verification and generate an App Password. Here's how:

  1. Go to your Gmail's Security settings.
  2. Under "Signing in to Google," enable Two-Step Verification.
  3. Click "App Passwords" and select "Other" as the device.
  4. Generate an App Password.

.env File Configuration

Update the .env file as follows, replacing the placeholder with your App Password:

  • MAIL_PASSWORD=Your_App_Password

Configuration Caching

After making changes to the .env file, run php artisan config:cache to clear the existing cache and prevent any conflicts.

Troubleshooting

If you encounter the following error:

[Swift_TransportException] Expected response code 250 but got code "535", with message "5.7.8 Username and Password not accepted. Learn more at 5.7.8 Username and Password not accepted - Gmail Help"

Solution: Ensure that your App Password is correct and that you have enabled Two-Step Verification for your Gmail account.

By following these steps, you can successfully send emails using Gmail in your Laravel application.

The above is the detailed content of How to Configure Gmail for Email Sending in Laravel Applications?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template