tosend/tosend-php
Composer 安装命令:
composer require tosend/tosend-php
包简介
Official PHP SDK for the ToSend email API
关键字:
README 文档
README
A simple PHP SDK for the ToSend email API.
Requirements
- PHP 7.4 or higher
- cURL extension
Installation
With Composer
composer require tosend/tosend-php
Without Composer
This SDK is a single file with no external dependencies. You can use it without Composer:
- Download
src/Api.phpfrom this repository - Place it anywhere in your project
- Include it in your code:
require_once 'path/to/Api.php'; $tosend = new ToSend\Api('tsend_your_api_key');
That's it! The SDK only requires PHP 7.4+ with the curl and json extensions, which are included in most PHP installations.
Quick Start
use ToSend\Api; $tosend = new Api('tsend_your_api_key'); $response = $tosend->send([ 'from' => [ 'email' => 'hello@yourdomain.com', 'name' => 'Your App' ], 'to' => [ ['email' => 'user@example.com'] ], 'subject' => 'Hello from ToSend!', 'html' => '<h1>Welcome!</h1><p>Thanks for signing up.</p>' ]); echo $response['message_id'];
Usage
Send an Email
$response = $tosend->send([ 'from' => [ 'email' => 'hello@yourdomain.com', 'name' => 'Your App' // optional ], 'to' => [ ['email' => 'user@example.com'], ['email' => 'another@example.com', 'name' => 'John Doe'] ], 'subject' => 'Welcome!', 'html' => '<h1>Hello</h1>', 'text' => 'Hello' // optional, auto-generated from HTML if not provided ]);
With CC, BCC, and Reply-To
$response = $tosend->send([ 'from' => ['email' => 'hello@yourdomain.com'], 'to' => [['email' => 'user@example.com']], 'cc' => [['email' => 'cc@example.com']], 'bcc' => [['email' => 'bcc@example.com']], 'reply_to' => ['email' => 'support@yourdomain.com', 'name' => 'Support'], 'subject' => 'Hello', 'html' => '<p>Hello World</p>' ]);
With Attachments
$response = $tosend->send([ 'from' => ['email' => 'hello@yourdomain.com'], 'to' => [['email' => 'user@example.com']], 'subject' => 'Your Invoice', 'html' => '<p>Please find your invoice attached.</p>', 'attachments' => [ [ 'type' => 'application/pdf', 'name' => 'invoice.pdf', 'content' => base64_encode(file_get_contents('invoice.pdf')) ] ] ]);
Batch Sending
Send multiple emails in a single request:
$response = $tosend->batch([ [ 'from' => ['email' => 'hello@yourdomain.com'], 'to' => [['email' => 'user1@example.com']], 'subject' => 'Hello User 1', 'html' => '<p>Hello!</p>' ], [ 'from' => ['email' => 'hello@yourdomain.com'], 'to' => [['email' => 'user2@example.com']], 'subject' => 'Hello User 2', 'html' => '<p>Hello!</p>' ] ]); foreach ($response['results'] as $result) { if ($result['status'] === 'success') { echo "Sent: " . $result['message_id'] . "\n"; } else { echo "Failed: " . $result['message'] . "\n"; } }
Get Account Info
$info = $tosend->getAccountInfo(); echo "Account: " . $info['account']['title'] . "\n"; echo "Emails this month: " . $info['account']['emails_usage_this_month'] . "\n"; foreach ($info['domains'] as $domain) { echo $domain['domain_name'] . ": " . $domain['verification_status'] . "\n"; }
Error Handling
use ToSend\Api; use ToSend\ToSendException; try { $response = $tosend->send([ 'from' => ['email' => 'hello@yourdomain.com'], 'to' => [['email' => 'user@example.com']], 'subject' => 'Hello', 'html' => '<p>Hello</p>' ]); } catch (ToSendException $e) { echo "Error: " . $e->getMessage() . "\n"; echo "Code: " . $e->getCode() . "\n"; // Get detailed validation errors foreach ($e->getErrors() as $field => $errors) { foreach ($errors as $key => $message) { echo "$field: $message\n"; } } }
API Reference
new Api(string $apiKey)
Create a new Api instance with your API key.
send(array $params): array
Send a single email. Returns ['message_id' => '...'] on success.
batch(array $emails): array
Send multiple emails. Returns ['results' => [...]] with status for each email.
getAccountInfo(): array
Get account and domain information.
setBaseUrl(string $url): self
Set a custom API base URL (useful for testing).
License
MIT
tosend/tosend-php 适用场景与选型建议
tosend/tosend-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「email」 「transactional」 「tosend」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tosend/tosend-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tosend/tosend-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tosend/tosend-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An updated fork (psr-0 to psr-4) from the original library "Mandrill/Mandrill" (https://bitbucket.org/mailchimp/mandrill-api-php)
A PSR-7 compatible library for making CRUD API endpoints
Sendernet transactional email php API client
Extensible library for building notifications and sending them via different delivery channels.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
Official Laravel SDK for the ToSend email API
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-24