How to Send Email in Laravel with Gmail SMTP

Sending email — for account verification, notifications, or password resets — is a must-have feature in many applications. Laravel makes it easy through the Mailable class. This ar...

How to Send Email in Laravel with Gmail SMTP
Advertisement

Sending email — for account verification, notifications, or password resets — is a must-have feature in many applications. Laravel makes it easy through the Mailable class. This article walks you through sending email using Gmail SMTP from scratch.

Step 1: Set Up a Gmail App Password

Gmail no longer allows SMTP login with your regular password. You need an App Password:

  1. Enable 2-step verification on your Google account.
  2. Go to Google Account → Security → App passwords.
  3. Create a new app password, then copy the 16 characters that appear.

Step 2: Configure .env

MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=youremail@gmail.com
MAIL_PASSWORD=your_16_character_app_password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=youremail@gmail.com
MAIL_FROM_NAME="Application Name"

After editing .env, run php artisan config:clear.

Advertisement

Step 3: Create a Mailable Class

php artisan make:mail WelcomeMail

Set the email content in app/Mail/WelcomeMail.php:

public function build()
{
    return $this->subject('Welcome!')
                ->view('emails.welcome');
}

Step 4: Create the Email View

Create the file resources/views/emails/welcome.blade.php:

<h1>Hello, {{ $name }}!</h1>
<p>Thank you for signing up for our application.</p>

Step 5: Send the Email

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

Mail::to('recipient@email.com')->send(new WelcomeMail());

Tip: Send Email Through a Queue

Sending email can be slow and hold up the response. It's better to run it through a queue so the page stays responsive:

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

Fixing Common Errors

  • "Failed to authenticate": You're using your regular password instead of an App Password. Use an App Password.
  • Connection timeout: wrong port/encryption — use port 587 with tls, or 465 with ssl.
  • Emails landing in spam: for serious production use, consider a service like Mailgun or Amazon SES with a verified domain.

Conclusion

Sending email in Laravel is straightforward: create a Gmail App Password, configure .env, build a Mailable plus a view, then send it with Mail::to(). For better performance, use a queue. Gmail is fine for development and low volume; for larger scale, switch to a dedicated email service.

Advertisement
kirim email laravel laravel smtp gmail mailable laravel konfigurasi email laravel laravel mail gmail
Share this article
Back to Blog
🚀 Partner Recommendation

Need Premium Source Code & Business Apps?

Access Laravel applications, POS systems, School Management, Clinic Software, ERP solutions, and ready-to-use premium source code at GudangCode.

GudangCode
  • ✔ Premium Source Code
  • ✔ Ready-to-Use Systems
  • ✔ Lifetime Updates
  • ✔ Lifetime Membership
  • ✔ Daily App Updates
Join Membership →
Advertisement
Latest Articles
Oct 14, 2026
Oct 13, 2026
Oct 11, 2026
Advertisement