Skip to main content

Sending Emails in Laravel with Gmail SMTP

This post will help you to fix issue like 
Error : Swift_TransportException in StreamBuffer.php line 268:
Connection could not be established with host smtp.gmail.com [Connection refused #111]

Sending emails is crucial for any web application. Usually, an email is sent to notify the user of some kind of activity.Here are the steps to send email in laravel using Gmail SMTP.
Generally Gmail is not recommended to send emails on live server, but if you just using it for testing purpose then follow these steps:
1. Visit https://myaccount.google.com/security make sure you have allowed less secure app to YES.
3. Generate APP password
  •  Turn on 2-Step Verification for your account  https://myaccount.google.com/security.
  • Your app might not support the latest security standards. Try changing a few settings to allow less secure apps access to your account.
  • After enabling 2-Step Verification, APP password option will be visible under Signing in to google
  • Create APP password

4. Update your .env to 
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465 
MAIL_USERNAME=email@gmail.com
MAIL_PASSWORD=APP_PASSWORD // created in step 3
MAIL_ENCRYPTION=ssl

5. run php artisan config:cache after you make changes in your .env file.
After performing above actions email should work fine.

Comments

Popular posts from this blog

Securing Your Emails: A Simple Guide to Email Authentication and Best Practices

Email security is crucial in today's digital landscape, and implementing authentication measures like DMARC, SPF, and DKIM can go a long way in safeguarding your domain. Here's an easy-to-follow guide to ensure your emails are authenticated and delivered securely: 1. Implement DMARC, SPF, and DKIM: Follow these steps for popular email services: Postmark Refer to the instructions provided in this link SendGrid Check the relevant information on their platform. Mailchimp Follow the recommended steps on their platform. 2. Validate Forward and Reverse DNS Records: Make sure your sending domains or IPs have valid forward and reverse DNS records (PTR records). Check resources for each service: Postmark Provides coverage for this aspect. SendGrid  Find the necessary information here Mailchimp Follow the guidelines specified by Mailchimp. 3. Maintain Low Spam Rates: Keep spam rates below 0.3% in Postmaster Tools and consider configuring Google Postmaster for additional insights into...

Complete guide: integrating POSTGIS with Laravel

PostGIS - It is an open-source software extension for the PostgreSQL relational database management system. It enables support for geographic objects and spatial queries, making it a powerful tool for working with geographic information systems (GIS) data. PostGIS allows you to store, manipulate, and analyze spatial data, such as points, lines, polygons, and other geometric objects. How to Setup PostGIS with Laravel To set up PostGIS with Laravel, you'll need to follow a few steps. PostGIS is an extension for PostgreSQL that allows you to work with geospatial data, and Laravel is a popular PHP framework. Before proceeding, ensure you have PostgreSQL installed on your server or local development environment. Here's a step-by-step guide to setting up PostGIS with Laravel: 1. Install Laravel: If you haven't already, install Laravel using Composer. Open your terminal and run the following command: composer create-project --prefer-dist laravel/laravel project-name 2. Configure...