Download the PHP package bobwez98/mail-log-laravel without Composer
On this page you can find all versions of the php package bobwez98/mail-log-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bobwez98/mail-log-laravel
More information about bobwez98/mail-log-laravel
Files in bobwez98/mail-log-laravel
Package mail-log-laravel
Short Description A module to log mails in laravel.
License MIT
Informations about the package mail-log-laravel
Laravel Mail Log
Automatically log outgoing Laravel emails and their send status to your application's database.
Requirements
- PHP 8.4+
- Laravel 13
Features
- Automatically logs mail through Laravel's native mail events
- Correlates sending and sent events with a unique
X-Mail-Log-IDheader - Stores senders, recipients, subject, message body, and mail event data
- Tracks when a message is pending and when it has been sent
- Provides an Eloquent model with enum, array, and datetime casts
- Can be disabled through configuration or an environment variable
Installation
Install the Composer package:
The service provider is registered through Laravel package discovery. Run the migrations to create the mail_logs table:
Configuration
Publish the configuration file:
The published configuration is available at config/mail-log-laravel.php:
Mail logging is enabled by default. It can be disabled in your .env file:
How It Works
Before Laravel sends an email, the package:
- Generates a unique message ID.
- Adds the ID to the email as an
X-Mail-Log-IDheader. - Creates a mail log with the
pendingstatus.
After Laravel dispatches the MessageSent event, the package uses the header to find the corresponding record, changes its status to success, and records when it was sent.
[!IMPORTANT] Exceptions raised while creating or updating mail logs are reported through Laravel's exception handler without interrupting mail delivery. Messages without a To recipient or subject are stored with empty values.
Usage
No changes to your mailables are required. Once installed and migrated, outgoing emails are logged automatically.
Using a framework?
Laravel mail log supports multiple frameworks to add a UI. For example:
- Statamic
- Nova - Coming soon
- Filament - Coming soon
Query the logs yourself
Mail logs can be queried through the included Eloquent model:
Each mail log contains the following data:
| Attribute | Description |
|---|---|
message_id |
Unique UUID used to correlate mail events |
status |
Current LogStatus value |
from |
Formatted sender addresses |
to |
Formatted recipient addresses |
subject |
Email subject |
body |
HTML or plain-text email body |
data |
Laravel mail event data |
sent_at |
Date and time Laravel dispatched the sent event |
The available statuses are pending and success.
Laravel dispatches MessageSending and MessageSent events, but it does not provide a MessageFailed event. If the mail transport throws an exception, the package cannot observe that through Laravel's mail events and the record remains pending. Applications that need to track these failures must catch exceptions around their mail sends themselves.
Quality
To ensure the quality of this package, run the following command:
This will execute five tasks:
- Checks if the code is correctly formatted
- Checks for issues using static code analysis
- Makes sure all tests pass
- Verifies 100% code coverage
- Checks for pending Rector changes
Code coverage requires Xdebug with coverage mode enabled.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please report security vulnerabilities privately to [email protected].
Credits
- Bob Wezelman
- All Contributors
License
The MIT License (MIT). Please see License File for more information.