agyanadda@gmail.com

Laravel Sending Email

Advanced Laravel 1 min read Updated Dec 2, 2026 Topic 25 of 31

Laravel sends email through Mailable classes — one class per kind of email (welcome, invoice, password reset).

Configure SMTP in .env

Set MAIL_MAILER=smtp, MAIL_HOST, MAIL_PORT, MAIL_USERNAME, MAIL_PASSWORD, MAIL_FROM_ADDRESS and MAIL_FROM_NAME using your email provider's details (Gmail app password, Hostinger mail, Mailgun, SES…).

While developing, use MAIL_MAILER=log: emails are written to storage/logs/laravel.log instead of being sent.

Create a mailable

php artisan make:mail WelcomeMail creates app/Mail/WelcomeMail.php with:

  • envelope() — the subject
  • content() — the Blade view used for the body
  • attachments() — files to attach

Public properties of the class are available in the view automatically.

Send it

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

Sending through SMTP takes a few seconds. Use ->queue(...) instead of ->send(...) to send it in the background (see the Queues lesson).

Example

Example — Welcome email PHP
<?php
// app/Mail/WelcomeMail.php
namespace App\Mail;

use App\Models\User;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;

class WelcomeMail extends Mailable
{
    public function __construct(public User $user) {}

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

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

// resources/views/emails/welcome.blade.php
// <h2>Hi {{ $user->name }},</h2>
// <p>Thanks for joining. Start learning today!</p>

// Controller
use Illuminate\Support\Facades\Mail;
Mail::to($user)->send(new WelcomeMail($user));

The user receives an email with the subject "Welcome to AgyanAdda!" and the body "Hi Asha, Thanks for joining...". With MAIL_MAILER=log it appears in storage/logs/laravel.log instead.

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which MAIL_MAILER value writes emails to the log file instead of sending them?

Exercise 2 True / False

Public properties of a Mailable are available in its Blade view.

Exercise 3 Fill in the Blank

Create a mailable with php artisan make:___ WelcomeMail

Frequently Asked Questions

Use a real domain email address in MAIL_FROM_ADDRESS, set up SPF, DKIM and DMARC records for your domain, and avoid sending from free Gmail addresses at volume. A transactional email service improves delivery.