lettermint/lettermint-php
Composer 安装命令:
composer require lettermint/lettermint-php
包简介
Official Lettermint PHP SDK.
README 文档
README
Integrate Lettermint in your PHP project.
Requirements
- PHP 8.2 or higher
- Composer
Installation
You can install the package via composer:
composer require lettermint/lettermint-php
Usage
Initialize the Lettermint client with your Sending API token:
$lettermint = new Lettermint\Lettermint('your-api-token');
For new integrations, prefer explicit clients for the two API surfaces:
$email = Lettermint\Lettermint::email(getenv('LETTERMINT_SENDING_TOKEN')); $api = Lettermint\Lettermint::api(getenv('LETTERMINT_API_TOKEN'));
Sending API tokens are project-specific and authenticate with the x-lettermint-token header. API tokens are team-scoped and authenticate with Authorization: Bearer .... Keep these tokens separate and never reuse an API token for sending-only workloads.
Sending Emails
The SDK provides a fluent interface for composing and sending emails:
$response = $lettermint->email ->from('sender@example.com') ->to('recipient@example.com') ->subject('Hello from Lettermint!') ->text('Hello! This is a test email.') ->send();
The SDK supports various email features:
$lettermint->email ->from('John Doe <john@example.com>') ->to('recipient1@example.com', 'recipient2@example.com') ->cc('cc@example.com') ->bcc('bcc@example.com') ->replyTo('reply@example.com') ->subject('Hello world!') ->html('<h1>Hello!</h1>') ->text('Hello!') ->headers(['X-Custom-Header' => 'Value']) ->attach('document.pdf', base64_encode($fileContent)) ->attach('logo.png', base64_encode($logoContent), 'logo@example.com') ->route('my-route-id') ->idempotencyKey('unique-request-id-123') ->send();
You can also send with an array payload:
$response = $email->send([ 'from' => 'sender@example.com', 'to' => ['recipient@example.com'], 'subject' => 'Hello from Lettermint!', 'text' => 'Hello! This is a test email.', ]);
Batch Sending
$response = $email->sendBatch([ [ 'from' => 'sender@example.com', 'to' => ['recipient@example.com'], 'subject' => 'First email', 'text' => 'Hello!', ], [ 'from' => 'sender@example.com', 'to' => ['another@example.com'], 'subject' => 'Second email', 'text' => 'Hello again!', ], ]);
Inline Attachments
You can embed images and other content in your HTML emails using content IDs:
$lettermint->email ->from('sender@example.com') ->to('recipient@example.com') ->subject('Email with inline image') ->html('<p>Here is an image: <img src="cid:logo@example.com"></p>') ->attach('logo.png', base64_encode($imageContent), 'logo@example.com') ->send();
Idempotency
To ensure that duplicate requests are not processed, you can use an idempotency key:
$response = $lettermint->email ->from('sender@example.com') ->to('recipient@example.com') ->subject('Hello from Lettermint!') ->text('Hello! This is a test email.') ->idempotencyKey('unique-request-id-123') ->send();
The idempotency key should be a unique string that you generate for each unique email you want to send. If you make the same request with the same idempotency key, the API will return the same response without sending a duplicate email.
For more information, refer to the documentation.
API Client
Use the API client for team-scoped resources such as projects, domains, routes, suppressions, stats, messages, and webhooks:
$api = Lettermint\Lettermint::api(getenv('LETTERMINT_API_TOKEN')); $projects = $api->projects->list(['filter[search]' => 'production']); $project = $api->projects->create([ 'name' => 'Production', 'smtp_enabled' => false, ]); $api->domains->verifyDnsRecords('domain-id'); $stats = $api->stats->retrieve([ 'from' => '2026-05-01', 'to' => '2026-05-09', ]); $api->suppressions->create([ 'email' => 'user@example.com', 'reason' => 'manual', 'scope' => 'team', ]); $api->webhooks->create([ 'route_id' => 'route-id', 'name' => 'Production webhook', 'url' => 'https://example.com/lettermint/webhook', 'events' => ['message.sent', 'message.delivered'], ]);
Both API surfaces support ping():
$email->ping(); $api->ping();
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Upgrading
Please see UPGRADE.md for guidance on upgrading from v1 to v2.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
lettermint/lettermint-php 适用场景与选型建议
lettermint/lettermint-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 108.81k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2025 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「lettermint」 「lettermint-php」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lettermint/lettermint-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lettermint/lettermint-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lettermint/lettermint-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Official Lettermint driver for Laravel
Symfony Lettermint Mailer Bridge
Alfabank REST API integration
Lettermint Mailer Adapter for Craft CMS.
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
A Lettermint mail driver for Flarum 2.0
统计信息
- 总下载量: 108.81k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 8
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-21