furqanmax/transactional-email
Composer 安装命令:
composer require furqanmax/transactional-email
包简介
A Laravel package to call a transactional email HTTP API with login, template send, and direct send.
README 文档
README
A lightweight package to call a transactional email HTTP API. It supports:
- Login to obtain a bearer token
- Template-based sends (
/gettransactionalApi) - Direct sends (
/makeTransactionalApi)
It works great in Laravel (auto-discovered provider + Facade) and can be used in any PHP project via Composer.
Installation
composer require furqanmax/transactional-email
Laravel auto-discovers the service provider. Optionally publish the config:
php artisan vendor:publish --tag=config --provider="Furqanmax\\TransactionalEmail\\TransactionalEmailServiceProvider"
Configuration
Config file: config/transactional-email.php
Environment variables you can set in Laravel:
APP_ID=37d26fe1-cb38-4fc4-8f53-00e6a6d115f2 # REQUIRED: your application UUID used for template sends TRANSACTIONAL_EMAIL_BASE_URL=http://127.0.0.1:8000/api TRANSACTIONAL_EMAIL_LOGIN_ENDPOINT=/login TRANSACTIONAL_EMAIL_TEMPLATE_ENDPOINT=/gettransactionalApi TRANSACTIONAL_EMAIL_DIRECT_ENDPOINT=/makeTransactionalApi TRANSACTIONAL_EMAIL_TIMEOUT=10 TRANSACTIONAL_EMAIL_VERIFY_SSL=false # Optional (enables auto-login if token is not set) TRANSACTIONAL_EMAIL_LOGIN_EMAIL=you@example.com TRANSACTIONAL_EMAIL_LOGIN_PASSWORD=secret
Usage in Laravel
You can use the Facade or inject the client.
- Facade:
Furqanmax\\TransactionalEmail\\Facades\\TransactionalEmail - Client:
Furqanmax\\TransactionalEmail\\TransactionalEmailClient
1) Login (get token)
use Furqanmax\\TransactionalEmail\\Facades\\TransactionalEmail; // Explicit login $token = TransactionalEmail::login('rohit@bizionictech.com', 'asdf'); // Or rely on configured credentials (env) for auto-login later
2) Send using a template
use Furqanmax\\TransactionalEmail\\Facades\\TransactionalEmail; $response = TransactionalEmail::sendTemplateEmail( from: 'pranita@bizionictech.com', to: 'pranita@bizionictech.com', templateKey: 'PRA_251125102142', templateVariables: [ 'name' => 'asdfas', 'reset_link' => 'www.bizionictech.com', 'otp' => '91991', ], subject: 'hello', preheaderText: 'hii everyone' );
By default, the client uses APP_ID as the UUID for template sends. To override per call, pass the optional uuid argument:
$response = TransactionalEmail::sendTemplateEmail( from: 'pranita@bizionictech.com', to: 'pranita@bizionictech.com', templateKey: 'WELCOME', templateVariables: ['name' => 'John'], uuid: 'override-uuid-here' );
3) Send a direct email (no template)
use Furqanmax\\TransactionalEmail\\Facades\\TransactionalEmail; $response = TransactionalEmail::sendDirectEmail( from: 'pranita@bizionictech.com', to: 'pranita@bizionictech.com', subject: 'Hello World', preheader: 'Redeem your gift $ card now.', body: "Hello,\n\nGreat news! You've received a $50 gift card from App Name.\n\n" . "Gift Card Code: GC123456789\nRedeem it here: [Redeem Link]\n\n" . "Enjoy!\n\nRegards,\nApp Name Team", htmlBody: '<!DOCTYPE html>...YOUR FULL HTML HERE...' );
Note: If you don't pass a $token, the client will automatically log in using configured credentials if present. Otherwise, call login() explicitly.
Dependency Injection example
use Furqanmax\\TransactionalEmail\\TransactionalEmailClient; class MailController { public function __construct(private TransactionalEmailClient $email) {} public function send() { // Auto-login based on env credentials if not logged in $resp = $this->email->sendDirectEmail( from: 'me@example.com', to: 'you@example.com', subject: 'Hi', body: 'Hello from DI!' ); return response()->json($resp); } }
Usage in plain PHP
- Require composer autoload and instantiate the client:
require __DIR__ . '/vendor/autoload.php'; use Furqanmax\\TransactionalEmail\\TransactionalEmailClient; $client = new TransactionalEmailClient( baseUrl: 'http://127.0.0.1:8000/api', endpoints: [ 'login' => '/login', 'template' => '/gettransactionalApi', 'direct' => '/makeTransactionalApi', ], httpConfig: [ 'timeout' => 10, 'verify_ssl' => false, ], credentials: [ 'email' => 'rohit@bizionictech.com', 'password' => 'asdf', ], appId: '37d26fe1-cb38-4fc4-8f53-00e6a6d115f2' // REQUIRED: application UUID (same as APP_ID in Laravel) ); // Optional explicit login $token = $client->login(); // Send using a template $templateResp = $client->sendTemplateEmail( from: 'pranita@bizionictech.com', to: 'pranita@bizionictech.com', templateKey: 'PRA_251125102142', templateVariables: [ 'name' => 'asdfas', 'reset_link' => 'www.bizionictech.com', 'otp' => '91991', ], subject: 'hello', preheaderText: 'hii everyone' ); // Send a direct email $directResp = $client->sendDirectEmail( from: 'pranita@bizionictech.com', to: 'pranita@bizionictech.com', subject: 'Hello World', preheader: 'Redeem your gift $ card now.', body: "Hello,\n\nGreat news! You've received a $50 gift card from App Name.\n\n" . "Gift Card Code: GC123456789\nRedeem it here: [Redeem Link]\n\n" . "Enjoy!\n\nRegards,\nApp Name Team", htmlBody: '<!DOCTYPE html>...YOUR FULL HTML HERE...' ); print_r([$templateResp, $directResp]);
Error handling
- All API calls return decoded JSON arrays on success.
- The client throws
RuntimeExceptionon HTTP errors (>= 400) or invalid JSON. - Wrap calls in
try/catchas needed.
try { $resp = TransactionalEmail::sendDirectEmail(...); } catch (\\Throwable $e) { // log/report }
Notes
- Requires PHP 8.1+ and cURL extension (
ext-curl). - Endpoints, base URL, and HTTP behavior are fully configurable via config/env in Laravel or constructor args in plain PHP.
- The client will auto-login using configured credentials when no token is provided.
- Template sends require a UUID: either configured via
APP_IDor provided per call asuuid.
License
MIT
furqanmax/transactional-email 适用场景与选型建议
furqanmax/transactional-email 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mail」 「package」 「api」 「email」 「laravel」 「transactional」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 furqanmax/transactional-email 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 furqanmax/transactional-email 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 furqanmax/transactional-email 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Courier offers a convenient and painless solution for creating emails tailored for your Kirby website.
A PSR-7 compatible library for making CRUD API endpoints
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.
Simple ASCII output of array data
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-29