PHPackages                             zanysoft/mail-tracker - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. zanysoft/mail-tracker

ActiveLibrary

zanysoft/mail-tracker
=====================

Logs and tracks all outgoing emails from Laravel

1.0(5y ago)22781MITPHPPHP &gt;=7.1

Since Dec 4Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/zanysoft/mail-tracker)[ Packagist](https://packagist.org/packages/zanysoft/mail-tracker)[ Docs](https://github.com/zanysoft/mail-tracker)[ RSS](/packages/zanysoft-mail-tracker/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (7)Versions (3)Used By (0)

MailTracker
===========

[](#mailtracker)

[![Latest Version on Packagist](https://camo.githubusercontent.com/92f20275651389e3c3b3fa5d7d2cbfa743055d1aabe920d8c181a15a2702951b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7a616e79736f66742f6d61696c2d747261636b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zanysoft/mail-tracker)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/03f9d7744b755e33e61956b128b8b76efeda6d303157e2588781223e84ca51dd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7a616e79736f66742f6d61696c2d747261636b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/zanysoft/mail-tracker)[![Travis](https://camo.githubusercontent.com/7c8f7e15e8d3e077292647cf22c58c679fa415ff025436b3a3a389fcd3628061/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f7a616e79736f66742f6d61696c2d747261636b65722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/zanysoft/mail-tracker)

MailTracker will hook into all outgoing emails from Laravel and inject a tracking code into it. It will also store the rendered email in the database. There is also an interface to view sent emails.

Install
-------

[](#install)

Via Composer

```
$ composer require zanysoft/mail-tracker
```

Publish the config file and migration

```
$ php artisan vendor:publish --provider="ZanySoft\MailTracker\MailTrackerServiceProvider"
```

Run the migration

```
$ php artisan migrate
```

Note: If you would like to use a different connection to store your models, you should update the mail-tracker.php config entry `connection` before running the migrations.

Usage
-----

[](#usage)

Once installed, all outgoing mail will be logged to the database. The following config options are available in config/mail-tracker.php:

- **name**: set your App Name.
- **inject-pixel**: set to true to inject a tracking pixel into all outgoing html emails.
- **track-links**: set to true to rewrite all anchor href links to include a tracking link. The link will take the user back to your website which will then redirect them to the final destination after logging the click.
- **expire-days**: How long in days that an email should be retained in your database. If you are sending a lot of mail, you probably want it to eventually expire. Set it to zero to never purge old emails from the database.
- **route**: The route information for the tracking URLs. Set the prefix and middlware as desired.
- **admin-route**: The route information for the admin. Set the prefix and middleware.
- **admin-template**: The params for the Admin Panel and Views. You can integrate your existing Admin Panel with the MailTracker admin panel.
- **date-format**: You can define the format to show dates in the Admin Panel.

If you do not wish to have an email tracked, then you can add the `X-No-Track` header to your message. Put any random string into this header to prevent the tracking from occurring. The header will be removed from the email prior to being sent.

```
\Mail::send('email.test', [], function ($message) {
    // ... other settings here
    $message->getHeaders()->addTextHeader('X-No-Track',Str::random(10));
});
```

Events
------

[](#events)

When an email is sent, viewed, or a link is clicked, its tracking information is counted in the database using the ZanySoft\\MailTracker\\Model\\SentEmail model. This processing is done via dispatched jobs to the default queue in order to prevent the database from being overwhelmed is an email blast situation.

You may want to do additional processing on these events, so an event is fired in these cases:

- ZanySoft\\MailTracker\\Events\\EmailSentEvent
- ZanySoft\\MailTracker\\Events\\ViewEmailEvent
- ZanySoft\\MailTracker\\Events\\LinkClickedEvent

If you are using the Amazon SNS notification system, these events are fired so you can do additional processing.

- ZanySoft\\MailTracker\\Events\\EmailDeliveredEvent (when you received a "message delivered" event, you may want to mark the email as "good" or "delivered" in your database)
- ZanySoft\\MailTracker\\Events\\ComplaintMessageEvent (when you received a complaint, ex: marked as "spam", you may want to remove the email from your database)
- ZanySoft\\MailTracker\\Events\\PermanentBouncedMessageEvent (when you receive a permanent bounce, you may want to mark the email as bad or remove it from your database)

To install an event listener, you will want to create a file like the following:

```
