tompec / laravel-email-log
A Laravel package to log outgoing emails
Installs: 1 373
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 2
Open Issues: 0
Requires
- php: ^7.2
- doctrine/dbal: ^2.10
- illuminate/database: ^6.0
- illuminate/support: ^6.0
Requires (Dev)
- orchestra/testbench: ^4.4.0
- phpunit/phpunit: ^8.0
README
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.