ghijk/laravel-email-preview
Composer 安装命令:
composer require ghijk/laravel-email-preview
包简介
A Laravel package for capturing and previewing emails in a web UI for staging/testing environments
README 文档
README
A Laravel package for capturing and previewing emails in a web UI, perfect for staging and testing environments.
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
1. Install via Composer
composer require ghijk/laravel-email-preview
2. Publish and Run Migrations
php artisan vendor:publish --tag=email-preview-migrations php artisan migrate
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
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
# 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
Add to app/Console/Kernel.php:
protected function schedule(Schedule $schedule) { $schedule->command('email-preview:cleanup')->daily(); }
Configuration
Publish Config (Optional)
php artisan vendor:publish --tag=email-preview-config
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
Update config/email-preview.php:
'routes' => [ 'middleware' => ['auth', 'admin'], // Your custom middleware ],
Frontend Views
The package uses Inertia.js and expects React components at:
resources/js/Pages/Admin/CapturedEmails/Index.tsxresources/js/Pages/Admin/CapturedEmails/Show.tsx
These components should be provided by your application for full UI customization.
API
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
All routes use the configured prefix and middleware:
GET /internal/emails- Email listGET /internal/emails/{uuid}- Email detailsDELETE /internal/emails/{uuid}- Delete emailDELETE /internal/emails- Clear all emails
How It Works
- Custom Mail Transport: Intercepts outgoing emails via custom
databasemail driver - Database Storage: Stores complete email data including HTML, text, headers, and attachments
- Web UI: Provides admin interface for viewing captured emails
- Auto-Cleanup: Optional command to remove old emails based on retention policy
Requirements
- PHP 8.1 or higher
- Laravel 10.0 or 11.0
- MySQL/PostgreSQL/SQLite (any Laravel-supported database)
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
MIT License. See LICENSE for more information.
Credits
Created by Wild at Heart
Support
For issues and feature requests, please use the GitHub issue tracker.
ghijk/laravel-email-preview 适用场景与选型建议
ghijk/laravel-email-preview 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 356 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ghijk/laravel-email-preview 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ghijk/laravel-email-preview 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 356
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-11