PHPackages                             ghijk/laravel-email-preview - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. ghijk/laravel-email-preview

ActiveLibrary[Testing &amp; Quality](/categories/testing)

ghijk/laravel-email-preview
===========================

A Laravel package for capturing and previewing emails in a web UI for staging/testing environments

v1.1.0(3mo ago)0359MITPHPPHP ^8.3CI passing

Since Jan 11Pushed 3mo agoCompare

[ Source](https://github.com/1stevengrant/laravel-email-preview)[ Packagist](https://packagist.org/packages/ghijk/laravel-email-preview)[ RSS](/packages/ghijk-laravel-email-preview/feed)WikiDiscussions main Synced today

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

Laravel Email Preview
=====================

[](#laravel-email-preview)

A Laravel package for capturing and previewing emails in a web UI, perfect for staging and testing environments.

Features
--------

[](#features)

- 📧 Capture all outgoing emails instead of sending them
- 🎨 View HTML and plain text versions of emails
- 🔍 Search and filter captured emails
- 📎 Download email attachments
- 🗄️ Store emails in database with auto-cleanup
- 🔐 Secure admin-only access
- ⚙️ Fully configurable routes and middleware
- 🎯 Zero configuration required for basic usage

Installation
------------

[](#installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require ghijk/laravel-email-preview
```

### 2. Publish and Run Migrations

[](#2-publish-and-run-migrations)

```
php artisan vendor:publish --tag=email-preview-migrations
php artisan migrate
```

### 3. Configure Mail Driver

[](#3-configure-mail-driver)

Set your mail driver to `database` in `.env`:

```
MAIL_MAILER=database
```

That's it! You're ready to start capturing emails.

Usage
-----

[](#usage)

### Viewing Captured Emails

[](#viewing-captured-emails)

Navigate to `/internal/emails` in your application (default route). The package provides:

- **Email List**: Paginated view of all captured emails with search and filters
- **Email Detail**: Full email preview with HTML/text toggle, headers, and attachments
- **Delete Options**: Delete individual emails or clear all

### Cleanup Old Emails

[](#cleanup-old-emails)

```
# Clean up emails older than 7 days (default)
php artisan email-preview:cleanup

# Custom retention period
php artisan email-preview:cleanup --days=30
```

### Scheduled Cleanup

[](#scheduled-cleanup)

Add to `app/Console/Kernel.php`:

```
protected function schedule(Schedule $schedule)
{
    $schedule->command('email-preview:cleanup')->daily();
}
```

Configuration
-------------

[](#configuration)

### Publish Config (Optional)

[](#publish-config-optional)

```
php artisan vendor:publish --tag=email-preview-config
```

### Available Options

[](#available-options)

Configure via `.env`:

```
# Table name for storing emails
EMAIL_PREVIEW_TABLE=captured_emails

# Number of days to retain emails
EMAIL_PREVIEW_RETENTION_DAYS=7

# Route configuration
EMAIL_PREVIEW_ROUTE_PREFIX=internal/emails
EMAIL_PREVIEW_ROUTE_NAME=internal.captured-emails
EMAIL_PREVIEW_MIDDLEWARE=auth,super_admin

# Enable/disable routes
EMAIL_PREVIEW_ROUTES_ENABLED=true

# Auto cleanup (still requires scheduler setup)
EMAIL_PREVIEW_AUTO_CLEANUP=false
```

### Custom Middleware

[](#custom-middleware)

Update `config/email-preview.php`:

```
'routes' => [
    'middleware' => ['auth', 'admin'], // Your custom middleware
],
```

Frontend Views
--------------

[](#frontend-views)

The package uses Inertia.js and expects React components at:

- `resources/js/Pages/Admin/CapturedEmails/Index.tsx`
- `resources/js/Pages/Admin/CapturedEmails/Show.tsx`

These components should be provided by your application for full UI customization.

API
---

[](#api)

### Model

[](#model)

```
use Ghijk\EmailPreview\Models\CapturedEmail;

// Query captured emails
$emails = CapturedEmail::query()
    ->search('test@example.com')
    ->mailableClass('App\\Mail\\WelcomeMail')
    ->dateRange('2024-01-01', '2024-12-31')
    ->get();

// Access email data
$email->to; // Array of recipients
$email->subject;
$email->html_body;
$email->text_body;
$email->attachments; // Array of attachment data
$email->mailable_class; // Original mailable class name
```

### Routes

[](#routes)

All routes use the configured prefix and middleware:

- `GET /internal/emails` - Email list
- `GET /internal/emails/{uuid}` - Email details
- `DELETE /internal/emails/{uuid}` - Delete email
- `DELETE /internal/emails` - Clear all emails

How It Works
------------

[](#how-it-works)

1. **Custom Mail Transport**: Intercepts outgoing emails via custom `database` mail driver
2. **Database Storage**: Stores complete email data including HTML, text, headers, and attachments
3. **Web UI**: Provides admin interface for viewing captured emails
4. **Auto-Cleanup**: Optional command to remove old emails based on retention policy

Requirements
------------

[](#requirements)

- PHP 8.1 or higher
- Laravel 10.0 or 11.0
- MySQL/PostgreSQL/SQLite (any Laravel-supported database)

Security
--------

[](#security)

- Always use appropriate middleware to restrict access
- Never use in production with real customer data
- Regularly clean up captured emails
- Review captured emails before deploying to production

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for more information.

Credits
-------

[](#credits)

Created by [Wild at Heart](https://wildatheart.org)

Support
-------

[](#support)

For issues and feature requests, please use the GitHub issue tracker.

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance79

Regular maintenance activity

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~65 days

Total

2

Last Release

109d ago

PHP version history (2 changes)v1.0.0PHP ^8.2

v1.1.0PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/10068142?v=4)[ghijk](/maintainers/ghijk)[@ghijk](https://github.com/ghijk)

---

Top Contributors

[![1stevengrant](https://avatars.githubusercontent.com/u/112473?v=4)](https://github.com/1stevengrant "1stevengrant (6 commits)")

###  Code Quality

TestsPest

Static AnalysisRector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/ghijk-laravel-email-preview/health.svg)

```
[![Health](https://phpackages.com/badges/ghijk-laravel-email-preview/health.svg)](https://phpackages.com/packages/ghijk-laravel-email-preview)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[flarum/core

Delightfully simple forum software.

201.4M2.3k](/packages/flarum-core)[api-platform/laravel

API Platform support for Laravel

58171.8k14](/packages/api-platform-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
