lopatin96/laravel-mail

Laravel mail

1.0.10 2023-11-16 15:33 UTC

This package is auto-updated.

Last update: 2024-12-16 17:51:57 UTC


README

Migrations

php artisan vendor:publish --tag="laravel-mail-migrations"

then run php artisan migrate

Listeners

Register an event listener in App\Providers\EventServiceProvider:

use Atin\LaravelMail\Listeners\LogSentMessage;
use Illuminate\Mail\Events\MessageSent;
 
/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    MessageSent::class => [
        LogSentMessage::class,
    ],
];

Generating Mailables

New "mailable" class will be stored in the app/Mail directory.

php artisan make:mail OrderShipped

Mailable class

Extend from Atin\LaravelMail\Mail\Mailable to log.

use Atin\LaravelMail\Mail\Mailable;

class UserConfirmEmail extends Mailable
{
    public function build()
    {
         // Build email
    }
}

Trait

Add HasMailLogs trait.

use Atin\LaravelMail\Traits\HasMailLogs;

class User extends Authenticatable
{
    use HasMailLogs;
    …
}

Migrations

php artisan vendor:publish --tag="laravel-mail-migrations"