Mail

Introduction

Lumen provides a clean, simple API over the popular SwiftMailer library with drivers for SMTP, Mailgun, SparkPost, Amazon SES, PHP's mail function, and sendmail, allowing you to quickly get started sending mail through a local or cloud based service of your choice.

Configuration

Before using Laravel's mail drivers in Lumen, you will need to install the illuminate/mail package via Composer. Then, you should register the Illuminate\Mail\MailServiceProvider in your bootstrap/app.php file:

  1. $app->register(Illuminate\Mail\MailServiceProvider::class);

Next, configure your mail options by copying the mail.php configuration file from the full Laravel framework to the config directory in the root of your project. Of course, you are free to adjust the configuration options as needed. If your Lumen application does not contain a config directory, you should create it.

After creating the configuration file, you should register the mailer and its aliases within your bootstrap/app.php file:

  1. $app->configure('mail');
  2. $app->alias('mailer', Illuminate\Mail\Mailer::class);
  3. $app->alias('mailer', Illuminate\Contracts\Mail\Mailer::class);
  4. $app->alias('mailer', Illuminate\Contracts\Mail\MailQueue::class);

The following configuration options should also be available to your Lumen application's .env file:

  1. MAIL_DRIVER=smtp
  2. MAIL_HOST=smtp.mailtrap.io
  3. MAIL_PORT=2525
  4. MAIL_USERNAME=
  5. MAIL_PASSWORD=
  6. MAIL_ENCRYPTION=tls
  7. [email protected]
  8. MAIL_FROM_NAME="Example app"

Usage

The Lumen mail drivers utilize the same code as the Laravel mail drivers. Beyond configuration, there are no differences between sending mail in Lumen and sending mail in Laravel; therefore, please consult the full Laravel documentation for usage examples.