laravel-email-log
logs outgoing emails sent to your users.
If you use MailGun, you can also track deliveries, failures, opens and clicks.
Install the package via composer:
composer require tompec/laravel-email-log
If you use Laravel 5.5+, the package will register itself, otherwise, add this to your config/app.php
'providers' => [
Tompec\EmailLog\EmailLogServiceProvider::class,
],
Run the migration:
php artisan migrate
Publish the configuration file:
php artisan vendor:publish --provider="Tompec\EmailLog\EmailLogServiceProvider"
Here's the content of the config file.
return [
/*
* This is the name of the table that will be created by the migration.
*/
'table_name' => 'email_log',
/*
* The model that will be attached to the email logs.
*/
'recipient_model' => \App\User::class,
/*
* This is the name of the column that the `recipient_model` uses to store the email address.
*/
'recipient_email_column' => 'email',
/*
* Whether or not you want to log emails that don't belong to any model
*/
'log_unknown_recipients' => true,
];
If you want to get all the email logs for your a user, add this to your App\User.php
file (or the model you chose as your recipient_model
):
public function email_logs()
{
return $this->morphMany(\Tompec\EmailLog\EmailLog::class, 'recipient');
}
Then you can do App\User::find(1)->email_logs
to retreive all the emails that this user has received.
If you use Mailgun, you can track these 4 events: delivered
, opened
, clicked
, permanent_fail
.
Add the following url as a new webhook.
https://www.yourdomain.com/email-log/mailgun
If you use Laravel Nova, you can create a new resource to view the content of the table:
php artisan nova:resource EmailLog
Then paste the content of this gist for a quick setup.
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email laravel-email-log@mail.tompec.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.