mahrdanial/shwanix-mailer
Composer 安装命令:
composer require mahrdanial/shwanix-mailer
包简介
Laravel mail driver that sends messages through the Shwanix HTTP mail API (JSON POST) instead of SMTP.
README 文档
README
Send Laravel mail through the Shwanix HTTP mail API (JSON POST) instead of SMTP. Works with standard Mail facades, Mailables, and queues.
Requirements: PHP ^8.0, Guzzle ^7.5, Laravel ^7.30 through ^12.0 (see below).
Laravel & PHP: Supports Laravel 7.30+ through 12.x (Composer cannot install this package on Laravel 7.0–7.29). Laravel 7 requires PHP 8 via 7.30.x for use with this package. Laravel 11+ needs PHP ^8.2 (framework requirement). Internally, Laravel 7–8 use a SwiftMailer transport (legacy/SwiftShwanixTransport.php); Laravel 9+ use Symfony Mailer (ApiTransport).
Installation
From your Laravel application root:
composer require mahrdanial/shwanix-mailer
The service provider is auto-discovered; you do not need to register it manually.
Publish the optional configuration file:
php artisan vendor:publish --tag=shwanix-mailer-config
This creates config/shwanix-mail.php (endpoint URL, API key, HTTP timeouts, SSL verification).
What MAIL_MAILER=shwanix does
Laravel’s mail stack is driven by config/mail.php. The mailer (sometimes called “driver” in docs) decides how messages are sent: smtp, log, array, etc.
Setting MAIL_MAILER=shwanix tells Laravel to use this package’s custom transport. The provider registers it with Mail::extend('shwanix', …), so the name shwanix must appear in your mailers config (see below). You can still use other mailers (smtp, log) for different messages via Mail::mailer('smtp'), etc.
Configuration
1. Environment (.env)
Required:
MAIL_MAILER=shwanix SHWANIX_MAIL_KEY=your-plain-secret
SHWANIX_MAIL_KEY is required. Use the plain secret registered for your app (validated server-side). It is sent as the api_key field in JSON (no attachments) or in multipart/form-data when files are attached.
Optional tuning (defaults are set in config/shwanix-mail.php):
SHWANIX_MAIL_TIMEOUT=30 SHWANIX_MAIL_CONNECT_TIMEOUT=10 SHWANIX_MAIL_VERIFY_SSL=true
The default API URL is defined in the published config/shwanix-mail.php file. Set SHWANIX_MAIL_URL in .env only when you need to override that value.
2. Mail config (config/mail.php)
Register the shwanix mailer under mailers:
'mailers' => [ // ... 'shwanix' => [ 'transport' => 'shwanix', ], ],
To use Shwanix for all outgoing mail by default:
'default' => env('MAIL_MAILER', 'shwanix'),
Usage
Use Laravel’s mail API as usual. Ensure SHWANIX_MAIL_KEY is set in .env so requests authenticate with the Shwanix API.
use Illuminate\Support\Facades\Mail; Mail::raw('Hello from Shwanix.', function ($message) { $message->to('user@example.com') ->subject('Test'); }); Mail::send('emails.welcome', $data, function ($message) { $message->to(['a@example.com', 'b@example.com']) ->cc('cc@example.com') ->subject('Welcome'); });
Explicit mailer:
Mail::mailer('shwanix')->send(...);
Behaviour
| Feature | Behaviour |
|---|---|
| Recipients | to: one string (comma-separated if multiple). cc / bcc: omitted when empty; otherwise a string for one address or a JSON array for several (matches the Shwanix API). Logs include recipient_count. |
| Body | Prefers HTML; otherwise plain text. |
| Attachments | With attachments: multipart/form-data with attachments[] file parts (decoded from Symfony/Swift parts). Without attachments: application/json with optional attachments as base64 objects. |
| Success | info log with recipient_count and HTTP status. |
| Failure | Non-2xx HTTP, Guzzle errors, or JSON { "status": false, "message": "..." } → TransportException and error logs. |
HTTP payload
- No attachments:
POSTasapplication/jsonwithapi_key,to,subject,body, and optionalcc/bcc(string or array of emails per the API). Noattachmentskey when there are none. - With attachments:
POSTasmultipart/form-data:api_key,to,subject,body, optionalcc/bcc(string or repeatedcc[]/bcc[]parts), and binaryattachments[]parts (filename + Content-Type from the mail part).
Responses are still treated as JSON when the server returns a JSON body (e.g. { "status": true }).
Implementation note (transport base class)
- Laravel 9+:
MailManageruses Symfony Mailer.ApiTransportextendsSymfony\Component\Mailer\Transport\AbstractTransport, like Laravel’s SES transport. - Laravel 7–8: Mail uses SwiftMailer. A dedicated
SwiftShwanixTransportextendsIlluminate\Mail\Transport\Transportand is loaded only on those versions (seelegacy/SwiftShwanixTransport.php).
Releasing
Tag a stable version so Composer can resolve a default release:
git tag v1.0.0 git push origin v1.0.0
Then install with:
composer require mahrdanial/shwanix-mailer
License
MIT.
mahrdanial/shwanix-mailer 适用场景与选型建议
mahrdanial/shwanix-mailer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 1, 最近一次更新时间为 2026 年 04 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mail」 「mailer」 「laravel」 「http-api」 「laravel-package」 「shwanix」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mahrdanial/shwanix-mailer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mahrdanial/shwanix-mailer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mahrdanial/shwanix-mailer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Courier offers a convenient and painless solution for creating emails tailored for your Kirby website.
Creates new sare mail transport for laravel applications
Mail libraries used by Zimbra Api
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
Mandrill Api Integration for Yii2
Laravel IMAP client
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 46
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-16