Search by

bobwez98 / mail-log-laravel

BobWez98

A module to log mails in laravel.

Package info

github.com/BobWez98/mail-log-laravel

Type:package

pkg:composer/bobwez98/mail-log-laravel

Statistics

Installs: 24

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-10-03 17:06 UTC

This package is auto-updated.

Last update: 2026-10-03 17:08:04 UTC


README

GitHub Workflow Status MIT Licensed Latest Version on Packagist

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-ID header
  • 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:

composer require bobwez98/mail-log-laravel

The service provider is registered through Laravel package discovery. Run the migrations to create the mail_logs table:

php artisan migrate

Configuration

Publish the configuration file:

php artisan vendor:publish --provider="BobWez98\MailLog\ServiceProvider" --tag=config

The published configuration is available at config/mail-log-laravel.php:

<?php

return [
    'enabled' => env('MAIL_LOG_ENABLED', true),
];

Mail logging is enabled by default. It can be disabled in your .env file:

MAIL_LOG_ENABLED=false

How It Works

Before Laravel sends an email, the package:

  1. Generates a unique message ID.
  2. Adds the ID to the email as an X-Mail-Log-ID header.
  3. Creates a mail log with the pending status.

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

Logged messages must contain a sender, recipient, subject, an HTML or plain-text body, and non-empty mail event data.

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:

<?php

use BobWez98\MailLog\Enums\LogStatus;
use BobWez98\MailLog\Models\MailLog;

$mailLogs = MailLog::query()
    ->latest()
    ->get();

$successfulMailLogs = MailLog::query()
    ->where('status', LogStatus::SUCCESS)
    ->latest()
    ->get();

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, success, and failed. The package automatically uses pending and success; failed is available for custom integrations.

Quality

To ensure the quality of this package, run the following command:

composer quality

This will execute five tasks:

  1. Checks if the code is correctly formatted
  2. Checks for issues using static code analysis
  3. Makes sure all tests pass
  4. Verifies 100% code coverage
  5. 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 info@bobwezelman.nl.

Credits

License

The MIT License (MIT). Please see License File for more information.