devlab-studio/laravel-mailer
Composer 安装命令:
composer require devlab-studio/laravel-mailer
包简介
This is my package laravel-mailer
README 文档
README
Laravel Mailer
Laravel package for advanced email sending with support for multiple SMTP senders, email logging and attachment management.
Summary
- Registers a custom channel to send notifications via SMTP configured per sender.
- Persists sent emails (body, metadata, status) and attachments to the database and storage (
storage/app/attachments/...). - Allows configuring SMTP senders via an interactive command or using
.envand a seeder.
Installation
Install via Composer:
composer require devlab-studio/laravel-mailer
Publish configuration (if applicable) and run migrations:
php artisan vendor:publish --tag=laravel-mailer-config php artisan migrate
SMTP Configuration (.env)
Before using the package, fill in your SMTP credentials in .env or use the interactive command:
MAIL_MAILER=smtpMAIL_HOST=your.smtp.hostMAIL_PORT=587MAIL_USERNAME=your@smtp.userMAIL_PASSWORD=secretMAIL_ENCRYPTION=tls# tls, ssl or nullMAIL_FROM_ADDRESS=from@example.comMAIL_FROM_NAME="Your Name"
Or run the interactive setup (it will save runtime config and run the seeder):
php artisan laravel-mailer
The command will ask for host, port, protocol, user, password, sender address and name and will run EmailSendersTableSeeder.
Senders Seeder
The EmailSendersTableSeeder inserts a sender into the email_senders table using current mail configuration (normally from .env). Run it manually:
php artisan db:seed --class=\\Devlab\\LaravelMailer\\Database\\Seeders\\EmailSendersTableSeeder
File: database/seeders/EmailSendersTableSeeder.php
Custom channel and send flow
The main channel is CustomMailChannel (src/CustomMail/CustomMailChannel.php) and does the following:
- Retrieves the recipient from the
notifiable. SupportsAnonymousNotifiable. - Resolves the sender (
from) from the message or from config (devlab.MAIL_FROM_ADDRESS). - Logs the email in the
emailstable storing HTML body, subject, to/cc/bcc and metadata. - Stores attachments in
storage/app/attachments/YYYY/M/D/and creates records inemails_attachments. - Selects which mailer to use by querying
email_senderstable:- If the sender exists, it dynamically creates a mailer
custom{ID}with the sender credentials (password decrypted) and uses it. - Otherwise it falls back to the default
smtpmailer.
- If the sender exists, it dynamically creates a mailer
- Sends the message using the selected mailer and updates the email record with status, sent date and errors if any.
Key files:
src/CustomMail/CustomMailChannel.phpsrc/Models/Email.php(logging and filters)src/Models/EmailsAttachment.php(attachment metadata)src/Models/EmailSender.php(SMTP senders)
Database structure
The package includes migrations in database/migrations to create:
email_senders— SMTP senders and credentials (password encrypted)emails— records of sent emails (body, status, to/cc/bcc, sent_at, etc.)emails_attachments— attachment metadata and storage paths
Check database/migrations for exact columns.
Attachments storage
Physical attachments are copied to storage/app/attachments/{year}/{month}/{day}/ and the path is recorded in the DB. The channel supports:
Illuminate\\Mail\\AttachmentIlluminate\\Http\\UploadedFile- Disk paths (strings)
Usage (quick example)
Inside a notification, implement toCustomMail() and return a Mailable or MailMessage with attachments and rawAttachments when needed. When notifying, the package:
// Notification public function toCustomMail($notifiable) { $mailable = new \\Illuminate\\Mail\\Mailable(); // configure view, subject, attachments, etc. return $mailable; } // Send $user->notify(new \\App\\Notifications\\MyNotification());
Errors and logging
On exception during sending, the channel captures the error, stores it on the email record and writes to the application log:
- Look for logs with
Log::error('CustomMailChannel error: ...')
Best practices & security
- Ensure SMTP credentials stored in the database are encrypted (the seeder uses
encrypt()during insert). - Protect access to
email_sendersif users can modify senders.
Useful commands
# Interactive setup and run seeder php artisan laravel-mailer # Run only the seeder php artisan db:seed --class=\\Devlab\\LaravelMailer\\Database\\Seeders\\EmailSendersTableSeeder # Run migrations (if not yet executed) php artisan migrate
Package entry file
The service provider registers config, migrations and the command:
src/LaravelMailerServiceProvider.php
Support
© 2026 Devlab Studio
devlab-studio/laravel-mailer 适用场景与选型建议
devlab-studio/laravel-mailer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 76 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 03 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「laravel-mailer」 「Devlab」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 devlab-studio/laravel-mailer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 devlab-studio/laravel-mailer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 devlab-studio/laravel-mailer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Неофициальный Laravel драйвер для Sendsay
Package to manage logs in Laravel applications.
Alfabank REST API integration
This is my package shopify-api-laravel
Symfony Zhylon Mailer Bridge
Laravel package for Accurate Online API integration.
统计信息
- 总下载量: 76
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-17