Skip to content

tompec/laravel-email-log

Repository files navigation

A Laravel package to log emails sent to your users

Latest Version on Packagist Build Status Quality Score Coverage StyleCI Total Downloads

laravel-email-log logs outgoing emails sent to your users. If you use MailGun, you can also track deliveries, failures, opens and clicks.

Installation

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

Configuration (optional)

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.

Webhooks

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

Laravel Nova

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.

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email laravel-email-log@mail.tompec.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.