mailbreeze/mailbreeze-php
Composer 安装命令:
composer require mailbreeze/mailbreeze-php
包简介
Official PHP SDK for MailBreeze - Email Marketing & Transactional Email Platform
README 文档
README
Official PHP SDK for MailBreeze - Email Marketing & Transactional Email Platform.
Requirements
- PHP 8.1 or higher
- Composer
Installation
composer require mailbreeze/mailbreeze-php
Quick Start
<?php use MailBreeze\MailBreeze; $client = new MailBreeze('your_api_key'); // Send an email $email = $client->emails->send([ 'from' => 'sender@yourdomain.com', 'to' => ['recipient@example.com'], 'subject' => 'Hello from MailBreeze!', 'html' => '<h1>Welcome!</h1><p>Thanks for signing up.</p>', ]); echo "Email sent with ID: " . $email['id'];
Features
- Transactional Emails - Send individual emails with tracking
- Contacts Management - Create, update, and manage contacts
- Lists - Organize contacts into lists
- Email Verification - Validate email addresses
- Attachments - Upload and attach files to emails
Usage Examples
Sending Emails
// Simple email $email = $client->emails->send([ 'from' => 'hello@yourdomain.com', 'to' => ['user@example.com'], 'subject' => 'Welcome!', 'html' => '<p>Hello World</p>', 'text' => 'Hello World', ]); // With template $email = $client->emails->send([ 'from' => 'hello@yourdomain.com', 'to' => ['user@example.com'], 'template_id' => 'tmpl_welcome', 'variables' => [ 'name' => 'John', 'company' => 'Acme Inc', ], ]); // With attachments $email = $client->emails->send([ 'from' => 'hello@yourdomain.com', 'to' => ['user@example.com'], 'subject' => 'Your Invoice', 'html' => '<p>Please find your invoice attached.</p>', 'attachment_ids' => ['attach_123'], ]); // Get email status $email = $client->emails->get('email_123'); // List emails $result = $client->emails->list([ 'status' => 'delivered', 'page' => 1, 'limit' => 20, ]); // Get statistics $stats = $client->emails->stats();
Managing Contacts
// Create contact $contact = $client->contacts->create([ 'email' => 'john@example.com', 'first_name' => 'John', 'last_name' => 'Doe', 'custom_fields' => [ 'company' => 'Acme Inc', 'plan' => 'enterprise', ], ]); // Update contact $contact = $client->contacts->update('contact_123', [ 'first_name' => 'Johnny', ]); // Get contact $contact = $client->contacts->get('contact_123'); // List contacts $result = $client->contacts->list([ 'status' => 'active', 'search' => 'john', ]); // Unsubscribe contact $client->contacts->unsubscribe('contact_123'); // Resubscribe contact $client->contacts->resubscribe('contact_123'); // Delete contact $client->contacts->delete('contact_123');
Managing Lists
// Create list $list = $client->lists->create([ 'name' => 'Newsletter Subscribers', 'description' => 'Weekly newsletter recipients', ]); // Add contact to list $client->lists->addContact('list_123', 'contact_456'); // Remove contact from list $client->lists->removeContact('list_123', 'contact_456'); // Get list contacts $result = $client->lists->contacts('list_123'); // Get list statistics $stats = $client->lists->stats('list_123');
Email Verification
// Verify single email $result = $client->verification->verify(['email' => 'user@example.com']); if ($result['is_valid']) { echo "Email is valid!"; } else { echo "Email is invalid: " . $result['status']; } // Batch verification $batch = $client->verification->batch([ 'email1@example.com', 'email2@example.com', 'email3@example.com', ]); // Check batch status $result = $client->verification->get($batch['verification_id']); // List verification jobs $verifications = $client->verification->list([ 'page' => 1, 'limit' => 20, ]); // Get verification statistics $stats = $client->verification->stats();
Attachments
// Create upload URL $upload = $client->attachments->createUploadUrl([ 'filename' => 'invoice.pdf', 'contentType' => 'application/pdf', 'size' => 102400, ]); // Upload file to the URL // Use your preferred HTTP client to PUT the file to $upload['uploadUrl'] // Use the attachment ID when sending emails $email = $client->emails->send([ 'from' => 'hello@yourdomain.com', 'to' => ['user@example.com'], 'subject' => 'Your Invoice', 'html' => '<p>Please find your invoice attached.</p>', 'attachmentIds' => [$upload['attachmentId']], ]);
Configuration Options
$client = new MailBreeze('your_api_key', [ 'base_url' => 'https://api.mailbreeze.com', // Custom API URL (default) 'timeout' => 30, // Request timeout in seconds 'max_retries' => 3, // Maximum retry attempts 'retry_delay' => 1000, // Base retry delay in milliseconds ]);
Error Handling
The SDK throws specific exceptions for different error types:
use MailBreeze\Exceptions\AuthenticationException; use MailBreeze\Exceptions\BadRequestException; use MailBreeze\Exceptions\NotFoundException; use MailBreeze\Exceptions\RateLimitException; use MailBreeze\Exceptions\ValidationException; use MailBreeze\Exceptions\ServerException; try { $email = $client->emails->send([...]); } catch (AuthenticationException $e) { // Invalid API key (401) echo "Authentication failed: " . $e->getMessage(); } catch (ValidationException $e) { // Validation errors (422) echo "Validation failed: " . $e->getMessage(); print_r($e->getErrors()); // Field-specific errors } catch (RateLimitException $e) { // Rate limited (429) echo "Rate limited. Retry after: " . $e->getRetryAfter() . " seconds"; } catch (NotFoundException $e) { // Resource not found (404) echo "Not found: " . $e->getMessage(); } catch (BadRequestException $e) { // Bad request (400) echo "Bad request: " . $e->getMessage(); } catch (ServerException $e) { // Server error (5xx) echo "Server error: " . $e->getMessage(); }
Automatic Retries
The SDK automatically retries failed requests with exponential backoff for:
- Connection errors
- Server errors (500, 502, 503, 504)
- Request timeouts (408)
Rate limit errors (429) are not retried automatically to respect the API limits.
License
MIT License - see LICENSE for details.
mailbreeze/mailbreeze-php 适用场景与选型建议
mailbreeze/mailbreeze-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「email」 「smtp」 「marketing」 「transactional」 「mailbreeze」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mailbreeze/mailbreeze-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mailbreeze/mailbreeze-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mailbreeze/mailbreeze-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.
The Message Submission Agent Diagnostics tool (msadiag) facilitates testing the compatibility of third party message submission agents.
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
PHPMailer helper class for sending emails using SMTP
An extension to Koldy Framework that brings integration for PHPMailer
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-25