Muhammad Yasir Amin

Loading websiteโ€ฆ

More from Muhammad Yasir Amin

Build Along With Me

Practical walkthroughs on Laravel, React, APIs and deployment workflows.

Subscribe on YouTube

How to Send Email Using Gmail SMTP in Laravel 13 with an App Password

๐Ÿ› ๏ธ Laravel Tutorials4 min read

How to Send Email Using Gmail SMTP in Laravel 13 with an App Password

Muhammad Yasir Amin

Muhammad Yasir Amin

Senior Full Stack Engineerโ€ขNov 12, 2026
How to Send Email Using Gmail SMTP in Laravel 13 with an App Password

To send email from Laravel 13 with Gmail, set the SMTP host to smtp.gmail.com, use port 587 with TLS (or 465 with SSL), and log in with your Gmail address and an app password, not your normal password. Google no longer allows "less secure apps", so the app password is the supported way. This guide has the exact .env values, a Mailable, a test route and fixes for typical errors.

Targets: Laravel 13 (PHP 8.3 to 8.5). Gmail SMTP is fine for testing and small projects; for production volume use a transactional email service.

Step 1: Create a Google app password

  1. Turn on 2-Step Verification for the Google account that will send the mail.
  2. Open the account security page and find App passwords. If you do not see it, the account may be managed by an organization or 2-Step Verification is not active.
  3. Create an app password with a name such as "Laravel" and copy the 16-character value.

Treat the app password like a real password. You can revoke it at any time from the same page.

Step 2: Configure .env

SQL
MAIL_MAILER=smtp
MAIL_SCHEME=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=your-address@gmail.com
MAIL_PASSWORD=your-16-character-app-password
MAIL_FROM_ADDRESS=your-address@gmail.com
MAIL_FROM_NAME="${APP_NAME}"

Port 587 uses STARTTLS and is the usual choice. If you prefer port 465 with implicit TLS, use MAIL_PORT=465 and set MAIL_SCHEME=smtps. Do not put the spaces from the Google display into the password; paste it without spaces.

After changing .env, clear the cached configuration:

Code
php artisan config:clear

Step 3: Create a Mailable

Code
php artisan make:mail WelcomeMail
JavaScript
<?php

namespace App\Mail;

use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;

class WelcomeMail extends Mailable
{
    public function __construct(public string $name) {}

    public function envelope(): Envelope
    {
        return new Envelope(subject: 'Welcome to our app');
    }

    public function content(): Content
    {
        return new Content(view: 'emails.welcome');
    }
}

Create the view at resources/views/emails/welcome.blade.php:

HTML / XML
<p>Hello {{ $name }},</p>
<p>Thanks for signing up.</p>

Step 4: Send a test email

PHP
use App\Mail\WelcomeMail;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Route;

Route::get('/send-test-mail', function () {
    Mail::to('recipient@example.com')->send(new WelcomeMail('Ali'));

    return 'Mail sent.';
})->middleware('auth');

Open the route while logged in and check the recipient's inbox (and the spam folder). Remove the route afterwards so nobody can use it to send mail.

You can also test from the terminal:

JavaScript
php artisan tinker --execute="Mail::raw('Test message', fn (\$m) => \$m->to('recipient@example.com')->subject('SMTP test'));"

How do I send email in the background?

SMTP calls take time. Queue the email so the user does not wait:

CSS
Mail::to($user)->queue(new WelcomeMail($user->name));

Run a queue worker (php artisan queue:work) so queued messages are sent. If you want a Mailable to always be queued, implement ShouldQueue on it.

Gmail sending limits

Google limits how many messages an account can send per day, and limits are lower for free accounts than for Google Workspace accounts. If you exceed them, sending is blocked for a while. Check Google's current limits before using Gmail for bulk or customer email, and move to a transactional email provider for production.

Common errors and fixes

  • Username and Password not accepted: you used the normal account password, or 2-Step Verification is off. Create an app password.
  • Connection timed out: your host blocks outgoing SMTP ports. Try the other port or ask the host.
  • Changes to .env ignored: run php artisan config:clear, and restart workers with php artisan queue:restart.
  • Mail lands in spam: make sure the From address matches the Gmail account that sends it.
  • App password option missing: 2-Step Verification must be on, and some managed accounts disable app passwords.

FAQ

Can I use my normal Gmail password?

No. Google blocks normal-password SMTP logins for ordinary accounts. Use an app password, or OAuth through a dedicated package.

Should I use Gmail SMTP in production?

For small internal apps it can work. For customer-facing email, use a service built for it, which gives better deliverability and clearer limits.

How do I see the email without sending it?

Set MAIL_MAILER=log. Laravel then writes the message to the log file instead of sending it.

References

Article Index & Topic Tags
LaravelSmtpEmailGmail

YouTube Channel

Build Along With Me

Practical walkthroughs on Laravel, React, APIs and deployment workflows.

Muhammad Yasir Amin
Available for Contracts
Author & Solutions Architect

Senior Full Stack Engineer

Independent Senior Full Stack Engineer working on Laravel, React and Next.js applications, APIs and delivery workflows.

Laravel & PHP ApplicationsReact & Next.js InterfacesREST APIs & IntegrationsDatabase Queries & DebuggingDocker Development WorkflowsClear Scope & Handover
Discuss Your Next Step

What Does Your Application Need Next?

Share your current system, the problem you want to solve and what a useful result looks like. We can identify the right starting point and agree on a practical scope.

Technical Audit

Find the Next Useful Fix

Application Development

Scoped, Reviewable Milestones

Ongoing Support

Agreed Capacity and Priorities

Share your goals, current stack and requirements before the call.