arrow_back
Back

Laravel mail: Mailables, Markdown, queues, and SMTP

Andrew Dorokhov Andrew Dorokhov schedule 1 min read
menu_book Table of Contents

Drivers for sending email:

  • SMTP
  • Mailgun
  • Postmark
  • Resend
  • Amazon SES
  • sendmail

Configuration

Laravel’s email services may be configured via your application’s config/mail.php configuration file.

These settings may be specified in .env:

MAIL_MAILER=smtp
MAIL_HOST=mailpit
MAIL_PORT=1025
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="hello@example.com"
MAIL_FROM_NAME="${APP_NAME}"

Driver / Transport

The API based drivers such as Mailgun, Postmark, Resend, and MailerSend are often simpler and faster than sending mail via SMTP servers. Whenever possible, we recommend that you use one of these drivers.

Mailgun:

composer require symfony/mailgun-mailer symfony/http-client
  • symfony/http-client: general package, Symfony Mailer bridge.
  • symfony/mailgun-mailer: Mailgun mailer.

Emails

Each email template should have a separate class extended from Mailable.

How to create a class using Artisan:

php artisan make:mail OrderConfirmed

Sending Mail

Example:

Mail::to('andrew@dorokhov.dev')->send(new MailableExample());

Pre-built templates with MD

open_in_new Docs on the Laravel websites.

Customizing Emails

Quite interesting open_in_new repo .

Testing Emails

Route::get('email-testing', function () {
    return new App\Mail\ExampleMailable();
});
code

Need Help with Development?

Happy to help — reach out via the contacts or go straight to my Upwork profile.

work View Upwork Profile arrow_forward