Sending emails is a core part of most web applications. In this tutorial, we’ll walk you through how to send emails in Laravel 12 using Gmail’s SMTP server with clear steps and sample images.
🛠️ Step 1: Install Laravel 12 Project
If you haven’t created a Laravel project yet, start with this:
🔑 Step 2: Enable Less Secure App Access in Gmail
To use Gmail SMTP, you need to allow access:
- Go to Google Account Security.
- Enable 2-Step Verification and generate an App Password.
- Use the app password in your
.env
file.
📝 Step 3: Configure .env
File
Open the .env
file in your project root and update mail configuration:
📤 Step 4: Create Mail Class
Run the artisan command to create a Mailable class:
Open app/Mail/TestEmail.php
and update:
🖼️ Step 5: Create Email View Blade File
Create a new view file:
And add:
🧪 Step 6: Send Email via Route or Controller
Option A: Using Route
Option B: Using Controller
Add the route:
✅ Step 7: Test in Browser
Start your Laravel server:
Open in browser:
If configured correctly, you’ll see:
Email Sent!
🧩 Bonus: Handle Email Failures
You can handle failures with:
📌 Conclusion
In this tutorial, you learned how to send emails from Laravel 12 using Gmail SMTP with step-by-step configuration and practical examples. Always make sure to use App Passwords for Gmail and never expose credentials in public repositories.