Download the PHP package jdavidbakr/mail-tracker without Composer
On this page you can find all versions of the php package jdavidbakr/mail-tracker. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jdavidbakr/mail-tracker
More information about jdavidbakr/mail-tracker
Files in jdavidbakr/mail-tracker
Package mail-tracker
Short Description Logs and tracks all outgoing emails from Laravel
License MIT
Homepage https://github.com/jdavidbakr/MailTracker
Informations about the package mail-tracker
MailTracker
[![Latest Version on Packagist][ico-version]][link-packagist] ![Software License][ico-license] [![Total Downloads][ico-downloads]][link-downloads] [![Travis][ico-travis]][link-travis]
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.
NOTE: If you are using Laravel 9.x you MUST be on version 9.6.0 or higher.
Upgrade from 4.x to 5.x
In 4.x and previous, there was a recipient
column in the sent_emails table that stored the RFC standard email format <Name> [email protected]
. 5.x has updated to store the name and email separately. The recipient
and sender
columns have been removed from the sent_emails
table migration, but no migration was added to drop those columns. Accessors have been added to retain the model's recipient
and sender
attributes, so no updates should need to be made to any code that currently uses those unless you are specifically querying the sender
or recipient
columns.
To retain your existing data afer upgrading, run the artisan command mail-tracker:migrate-recipients
. This will convert the existing recipient
and sender
data into the new format. At this point you may drop the recipient
and sender
columns.
There is also a new pair of attributes in the sent_emails
table: opened_at
and clicked_at
. Those store the first time the user opened and clicked, respectively. This has been added to the default tracker index page. You are welcome to add it into yours, or use those values as you see fit.
Upgrade from 3.x to 4.x
There are no breaking changes from 3.x to 4.x with the exception that 4.x is for Laravel 7+ only.
Upgrade from 2.x to 3.x
There was a breaking change with the update to version 3.0, specifically regarding the events that are fired. If you are listening for the PermanentBouncedMessageEvent
to catch all undeliverables, there are now two separate events: PermanentBouncedMessageEvent
will be fired only on permanent bounces, and a new event ComplaintMessageEvent
will be fired on complaints. There is also an new event EmailDeliveredEvent
that is fired for each successful delivery event. For information about setting up the SES/SNS environment to receive notifications regarding these events, see the documentation below.
Upgrade from 2.0 or earlier
First, upgrade to version 2.2 by running:
If you are updating from an earlier version, you will need to update the config file and run the new migrations. For best results, make a backup copy of config/mail-tracker.php and the views in resources/views/vendor/emailTrackingViews (if they exists) to restore any values you have customized, then delete that file and run
Also note that the migration for the sent_emails_url_clicked
table changed with version 2.1.13. The change is that the URL column is now a TEXT
field to allow for longer URLs. If you have an old system you may want to manually change that column; there is no migration included to perform that update.
Install
Via Composer
Publish the config file and migration
Run the migration
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.
If you would like to use your own migrations, you can skip this library migrations by calling MailTracker::ignoreMigrations()
. For example:
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.
- content-max-size: You can overwrite default maximum length limit for
content
database field. Do not forget update it's type fromtext
if you need to make it longer.
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.
Storing content of mails in filesystem
By default, the content of an e-mail is stored in the content
column in the database so that the e-mail can be viewed after it has been sent.
If a lot of emails are sent, this can consume a lot of memory and slow down the database overall. It is possible to specify in the configuration that the content should be saved to a file in the file system.
` To use the filesystem you need to change the
log-content-strategyfrom
databaseto
filesystem. You can specify the disk with
tracker-filesystemand the folder it should store the file in with
tracker-filesystem-folder`.
Overriding models
In some cases you want to override the built-in models. You can do so easily for example in you AppServiceProvider
with
Your model should implement to SentEmailModel
or SentEmailUrlClickedModel
interface. This package provides traits to easily implement your own models but not have to reimplement or copy existing code.
Skip Tracking for Specific Emails
If you have a specific email that you do not want to track, you can add the X-No-Track
header to the email. This will prevent the email from being tracked. The header will be removed from the email prior to being sent.
In laravel 9 onwards you can introduce a headers method to your Mailable class. This will stop the tracking pixel/click tracking from applying to the Mailable
Skipping Open/Click Tracking for Anti-virus/Spam Filters
Some mail servers might scan emails before they deliver which can trigger the tracking pixel, or even clicked links. You can add an event listener to the ValidActionEvent to handle this.
Ensure you add the listener to the ValidActionEvent
in your EventServiceProvider
, if you aren't using automatic event discovery.
php
public function handle(EmailSentEvent $event) { $tracker = $event->sent_email; $model_id = $event->sent_email->getHeader('X-Model-ID'); $model = Model::find($model_id); // Perform your tracking/linking tasks on $model knowing the SentEmail object }
Note that the headers you are attaching to the email are actually going out with the message, so do not store any data that you wouldn't want to expose to your email recipients.
## Exceptions
The following exceptions may be thrown. You may add them to your ignore list in your exception handler, or handle them as you wish.
- jdavidbakr\MailTracker\Exceptions\BadUrlLink - Something went wrong with the url link. Basically, the system could not properly parse the URL link to send the redirect to.
## Amazon SES features
If you use Amazon SES, you can add some additional information to your tracking. To set up the SES callbacks, first set up SES notifications under your domain in the SES control panel. Then subscribe to the topic by going to the admin panel of the notification topic and creating a subscription for the URL you copied from the admin page. The system should immediately respond to the subscription request. If you like, you can use multiple subscriptions (i.e. one for delivery, one for bounces). See above for events that are fired on a failed message. **For added security, it is recommended to set the topic ARN into the mail-tracker config.**
## Views
When you run the `php artisan vendor:publish` command, simple views will add to your resources/views/vendor/emailTrakingViews that you can customize. You of course my build your entire admin pages from scratch using these views as a guide.
## Admin Panel
MailTracker comes with a built-in administration area. The default configuration that is published with the package puts it behind the `can:see-sent-emails` middleware; you may create a gate for this rule or change it to use one of your own. You may also change the default prefix as well as disable the admin routes completely.
The route name is 'mailTracker_Index'. The standard admin panel route is located at /email-manager. You can use route names to include them into your existing admin menu. You can customize your route in the config file. You can see all sent emails, total opens, total urls clicks, show individuals emails and show the urls clicked details.
All views (email tamplates, panel) can be customized in resources/views/vendor/emailTrakingViews.
## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.
## Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## Credits
- [J David Baker][link-author]
- [All Contributors][link-contributors]
## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
[ico-version]: https://img.shields.io/packagist/v/jdavidbakr/mail-tracker.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/jdavidbakr/mail-tracker/master.svg?style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/jdavidbakr/MailTracker.svg?style=flat-square
[ico-code-quality]: https://img.shields.io/scrutinizer/g/jdavidbakr/MailTracker.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/jdavidbakr/mail-tracker.svg?style=flat-square
[link-packagist]: https://packagist.org/packages/jdavidbakr/mail-tracker
[link-travis]: https://travis-ci.com/jdavidbakr/mail-tracker
[link-scrutinizer]: https://scrutinizer-ci.com/g/jdavidbakr/MailTracker/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/jdavidbakr/MailTracker
[link-downloads]: https://packagist.org/packages/jdavidbakr/mail-tracker
[link-author]: https://github.com/jdavidbakr
[link-contributors]: ../../contributors
All versions of mail-tracker with dependencies
illuminate/support Version ^10.0|^11.0
guzzlehttp/guzzle Version ^7.2
aws/aws-php-sns-message-validator Version ^1.8
aws/aws-sdk-php Version ^3.258