Email providers

Local / Testing

Mailtrap

I personally use Mailtrap for emails in local environment, so it’s my recommendation. This doesn’t mean other services mentioned below are worse or better in any way.

https://laravel.com/docs/11.x/mail#mailtrap

  1. Create and setup Mailtrap account
  2. Update .env file with Mailtrap credentials
MAIL_MAILER=smtp
MAIL_HOST=sandbox.smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=your-mailtrap-username
MAIL_PASSWORD=your-mailtrap-password
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS="[email protected]"

HELO

Coming soon…

Mailpit

Coming soon…

Production / Staging

doesn’t come with any pre-installed email service since there is not one that fits all cases, and it’s actually very easy to setup any of the services mentioned below.

To implement desired mail service, just follow the instructions below or official Laravel docs.

Mailgun

Coming soon…

Postmark

Coming soon…

Resend

Coming soon…

MailerSend

  1. Install the package:
composer require mailersend/laravel-driver
  1. Create a MailerSend account.

Once your are logged in, go to Email - Domains to add your domain. You should also approve your account to avoid limitations.

  1. Go to Integrations and create API token for your domain. Update your .env file:
MAIL_MAILER=mailersend
MAILERSEND_API_KEY=your-api-key
MAIL_FROM_ADDRESS=[email protected]
  1. Add MailerSend to config/mail.php configuration file inside mailers array:
'mailersend' => [
    'transport' => 'mailersend',
],

Custom

https://laravel.com/docs/11.x/mail#custom-transports

Coming soon…

Queue emails

All emails are sent using Laravel’s deferred functions. If you need to send large amount of emails it’s recommended to send them in queues.

Setup local queue

https://laravel.com/docs/11.x/mail#queueing-mail

Docs coming soon…

Setup queue worker

Docs coming soon…

Laravel Horizon

Docs coming soon…

Previews emails

You can preview emails in local environment.

Preview routes are defined in routes/emails.php route file.

Here is the list of all email preview routes (each route is prefixed with /email-previews):

  • /email-verification Email sent upon user registration (when email verification is enabled)
  • /password-reset Email sent upon password reset request
  • /subscribed Email sent upon successful subscription

Email templates

Default emails are rendered using markdown files located in resources/views/mail folder.

Main message layout: resources/views/vendor/mail/html/message.blade.php

// Default title "Hello!"
<x-mail::message>
    // Mail content here
</x-mail::message>

// Custom title
<x-mail::message :title="$title">
    // Mail content here
</x-mail::message>

// If no title and user model is provider, the title will be "Hello, :name!" where name is user's name
// You can also pass url and action text, which will display subcopy in cases where button is not rendered
<x-mail::message :user="$user" :url="$url" :action-text="$actionText">
    // Mail content here
</x-mail::message>

List of all components used in email templates are located in resources/views/vendor/mail/html folder:

  • layout: Main HTML file to render email template. You should probably leave this as-is.
  • header: Application name with link to website, positioned above the content. You can update it to show your logo or anything relevant.
  • footer: Copyright text below the content.
  • panel: Highlighted text block.
  • table: Table block.
  • button: Action button. Accepts three parameters: color: primary (default), blue, green/success, red/error; url and align: left, right, center (default). You can add custom colors to default.css button-{color_name}
<x-mail::button color="green" :url="$url" align="left">
    @lang('Click me')
</x-mail::button>
  • subcopy: Smaller text used as disclaimer.
  • salutation: Included in message component.

To change style, you can update resources/views/vendor/mail/html/themes/default.css CSS file.