https://github.com/tompec/laravel-email-log
A Laravel package to log emails sent to your users
https://github.com/tompec/laravel-email-log
email laravel logging
Last synced: 3 months ago
JSON representation
A Laravel package to log emails sent to your users
- Host: GitHub
- URL: https://github.com/tompec/laravel-email-log
- Owner: tompec
- License: mit
- Created: 2020-01-04T08:30:43.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-05-23T01:01:36.000Z (about 2 years ago)
- Last Synced: 2025-12-14T10:28:06.106Z (6 months ago)
- Topics: email, laravel, logging
- Language: PHP
- Size: 43.9 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# A Laravel package to log emails sent to your users
[](https://packagist.org/packages/tompec/laravel-email-log)
[](https://travis-ci.org/tompec/laravel-email-log)
[](https://scrutinizer-ci.com/g/tompec/laravel-email-log)
[](https://scrutinizer-ci.com/g/tompec/laravel-email-log)
[](https://styleci.io/repos/231732412)
[](https://packagist.org/packages/tompec/laravel-email-log)
`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:
```bash
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`
``` php
'providers' => [
Tompec\EmailLog\EmailLogServiceProvider::class,
],
```
Run the migration:
```bash
php artisan migrate
```
## Configuration (optional)
Publish the configuration file:
```bash
php artisan vendor:publish --provider="Tompec\EmailLog\EmailLogServiceProvider"
```
Here's the content of the config file.
```php
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`):
```php
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](https://www.mailgun.com/), you can track these 4 events: `delivered `, `opened`, `clicked`, `permanent_fail`.
Add the following url [as a new webhook](https://documentation.mailgun.com/en/latest/user_manual.html#webhooks).
``` bash
https://www.yourdomain.com/email-log/mailgun
```
## Laravel Nova
If you use [Laravel Nova](https://nova.laravel.com/), you can create a new resource to view the content of the table:
``` bash
php artisan nova:resource EmailLog
```
Then paste the content of [this gist](https://gist.github.com/tompec/53108f575aa277102fdcca5e14543c06) for a quick setup.
## Testing
``` bash
composer test
```
## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) 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
- [Thomas Petracco](https://www.tompec.com/) ([GitHub](https://github.com/tompec))
- [All Contributors](../../contributors)
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.