Trying to get Laravel 5 email to work
Stefan Izdrail
Founder & Senior Architect · 2026-06-29
Title: Solving Common Issues When Setting Up Laravel Email with Gmail
Introduction
Sending emails from your application can be a crucial functionality that helps you improve user engagement and communication. In Laravel, this process is simple when using the built-in Mail facade. However, sometimes, errors might occur while configuring the mailer for Gmail, such as the one you are experiencing: "Swift_TransportException in AbstractSmtpTransport.php line 383: Expected response code 250 but got code '530', with message '530 5.7.1 Authentication required'."
In this blog post, we will discuss some common issues and provide solutions to help you get Laravel 5 emailing functionality working smoothly with Gmail.
Step-by-Step Guide for Setting Up Email Configuration with Gmail
1. Set up the mail driver in your .env file: First, ensure that the MAIL_DRIVER is set to 'smtp'. Then, configure the other necessary settings, such as MAIL_HOST to smtp.gmail.com, MAIL_PORT to 465 (Gmail uses port 465 for TLS encryption, instead of the default 587 which you have in your code), and MAIL_ENCRYPTION to tls.
2. Generate Application-Specific Passwords: To enable less sensitive access to your email account, Gmail supports generating application-specific passwords. Visit Google's Security page, navigate to 'App Passwords,' and click on the option that says 'Generate new password.' Select the appropriate app (email) from the dropdown menu and name it 'Laravel Mailer'. Copy this generated password for later use.
3. Update Your mail.php Configuration: In your MAIL_CONFIG array, update the values as follows:
- Change 'username' with the email address you used to generate an application-specific password (e.g., MyUsername@gmail.com).
- Replace 'password' with the newly generated application-specific password for this app ('Laravel Mailer').
4. Enable Less Secure Apps Setting: To bypass strict Gmail security measures and improve your chances of successful email delivery, enable "Allow less secure apps" in your Google account settings. This setting allows third-party applications like Laravel to access your account more freely. However, this method is not recommended for increased security reasons.
5. Run the Application: Now you can test sending emails using your configured Mail facade. If facing issues, consider reviewing the error messages and double-checking your configurations. You might want to try disabling "Allow less secure apps" in the future when developing locally or on a closed network.
Conclusion
By following these instructions, you can set up an efficient and secured emailing functionality for Laravel 5 with Gmail. If you still encounter issues, ensure you have checked all configurations and double-checked your environment settings. Finally, consider consulting the official Laravel documentation or seeking support from a community forum if needed. With a little patience and persistence, you can make Laravel's emailing functionality work smoothly.