sendlayer/sendlayer-php
Composer 安装命令:
composer require sendlayer/sendlayer-php
包简介
Official PHP SDK for SendLayer API
关键字:
README 文档
README
SendLayer PHP SDK
The official PHP SDK for interacting with the SendLayer API, providing a simple and intuitive interface for sending emails, managing webhooks, and retrieving email events.
Features
- Email Sending: Send transactional emails with support for HTML, text, attachments, and advanced options
- Webhook Management: Create, retrieve, and delete webhooks for real-time event notifications
- Event Tracking: Retrieve email events and analytics data
- Error Handling: Comprehensive exception handling with specific error types
- Validation: Built-in validation for email addresses, URLs, and API parameters
- File Attachments: Support for both local and remote file attachments
- Modern PHP: Built with PHP 7.4+ features and PSR-4 autoloading
Installation
Using Composer (Recommended)
composer require sendlayer/sendlayer-php
Manual Installation
- Download the SDK
- Include the autoloader in your project
- Install dependencies:
composer install
Quick Start
<?php require_once 'vendor/autoload.php'; use SendLayer\SendLayer; use SendLayer\Exceptions\SendLayerException; // Initialize the SDK with your API key $sendlayer = new SendLayer('your-api-key-here'); try { // Send a simple email $response = $sendlayer->Emails->send( from: 'sender@example.com', to: 'recipient@example.com', subject: 'Test Email', text: 'This is a test email sent using the SendLayer PHP SDK' ); echo "Email sent successfully! Message ID: " . $response['MessageID']; } catch (SendLayerException $e) { echo "Error: " . $e->getMessage(); }
Configuration (Optional)
You can pass additional configuration options when initializing the SDK:
$config = [ 'timeout' => 30, // HTTP timeout in seconds 'attachmentURLTimeout' => 30000, // Attachment URL timeout in milliseconds 'guzzle' => [ // Additional Guzzle HTTP client options 'verify' => false, // Disable SSL verification (not recommended for production) 'proxy' => 'http://proxy:8080' // Use proxy ] ]; $sendlayer = new SendLayer('your-api-key-here', $config);
Email Sending
Basic Email
$response = $sendlayer->Emails->send( from: 'sender@example.com', to: 'recipient@example.com', subject: 'Welcome!', text: 'Welcome to our platform!' );
HTML Email
$response = $sendlayer->Emails->send( from: 'sender@example.com', to: 'recipient@example.com', subject: 'Welcome!', html: '<h1>Welcome!</h1><p>Welcome to our platform!</p>' );
Email with Sender Name
$response = $sendlayer->Emails->send( from: ['email' => 'sender@example.com', 'name' => 'John Doe'], to: 'recipient@example.com', subject: 'Welcome!', text: 'Welcome to our platform!' );
Multiple Recipients
$response = $sendlayer->Emails->send( from: 'sender@example.com', to: ['user1@example.com', 'user2@example.com'], subject: 'Welcome!', text: 'Welcome to our platform!' );
Email with CC and BCC
$response = $sendlayer->Emails->send( from: 'sender@example.com', to: 'recipient@example.com', subject: 'Welcome!', text: 'Welcome to our platform!', cc: 'cc@example.com', bcc: 'bcc@example.com' );
Email with Attachments
$response = $sendlayer->Emails->send( from: 'sender@example.com', to: 'recipient@example.com', subject: 'Document attached', text: 'Please find the attached document.', attachments: [ [ 'path' => '/path/to/document.pdf', 'type' => 'application/pdf' ], [ 'path' => 'https://example.com/image.jpg', 'type' => 'image/jpeg' ] ] );
Email with Custom Headers and Tags
$response = $sendlayer->Emails->send( from: 'sender@example.com', to: 'recipient@example.com', subject: 'Welcome!', text: 'Welcome to our platform!', headers: [ 'X-Custom-Header' => 'Custom Value', 'X-Priority' => '1' ], tags: ['welcome', 'onboarding'] );
Webhook Management
Create a Webhook
$response = $sendlayer->Webhooks->create( url: 'https://your-domain.com/webhook', event: 'delivery' );
Get All Webhooks
$webhooks = $sendlayer->Webhooks->get();
Delete a Webhook
$sendlayer->Webhooks->delete(webhookId: 123);
Event Tracking
Get All Events
$events = $sendlayer->Events->get();
Get Events with Filters
$events = $sendlayer->Events->get( startDate: new DateTime('2024-01-01'), endDate: new DateTime('2024-01-31'), event: 'delivered', retrieveCount: 50 );
Get Events for Specific Message
$events = $sendlayer->Events->get( messageId: 'message-id-here' );
Error Handling
The SDK provides specific exception types for different error scenarios:
use SendLayer\Exceptions\SendLayerException; try { $response = $sendlayer->Emails->send(/* ... */); } catch (SendLayerException $e) { // Handle other SendLayer errors echo "Error: " . $e->getMessage(); }
Exception Types
SendLayerException: Base exception for all SendLayer errorsSendLayerAuthenticationException: Invalid API key or authentication issuesSendLayerValidationException: Invalid parameters or validation errorsSendLayerAPIException: API-specific errors with status code and response dataSendLayerNotFoundException: Resource not found (404 errors)SendLayerRateLimitException: Rate limit exceeded (429 errors)SendLayerInternalServerException: Server errors (5xx errors)
Supported Events
Webhook Events
bounce: Email bouncedclick: Link was clickedopen: Email was openedunsubscribe: User unsubscribedcomplaint: User marked as spamdelivery: Email was delivered
Event Tracking Events
accepted: Email was accepted by the serverrejected: Email was rejecteddelivered: Email was deliveredopened: Email was openedclicked: Link was clickedunsubscribed: User unsubscribedcomplained: User marked as spamfailed: Email delivery failed
Requirements
- PHP 7.4 or higher
- Guzzle HTTP Client 7.0 or higher
- JSON extension
- cURL extension (recommended)
License
This SDK is licensed under the MIT License. See the LICENSE file for details.
Support
For support, please contact:
- Email: support@sendlayer.com
- Documentation: https://developers.sendlayer.com
- GitHub Issues: https://github.com/sendlayer/sendlayer-php/issues
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Changelog
See CHANGELOG.md for a list of changes and version history.
sendlayer/sendlayer-php 适用场景与选型建议
sendlayer/sendlayer-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 801 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 08 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「email」 「sdk」 「send email」 「sendlayer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sendlayer/sendlayer-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sendlayer/sendlayer-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sendlayer/sendlayer-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
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.
Laravel contact us form package to send email and save to database
Alfabank REST API integration
A plugin for saving emails to a list
统计信息
- 总下载量: 801
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-28