sentd / sentd-php
Official PHP SDK for the SENTD Email API
dev-main
2026-01-25 15:04 UTC
Requires
- php: >=8.1
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2026-03-25 15:43:33 UTC
README
Official PHP client for the SENTD Email API.
Requirements
- PHP 8.1 or higher
- Composer
Installation
composer require sentd/sentd-php
Quick Start
<?php require_once 'vendor/autoload.php'; use Sentd\Sentd; // Create a new client $sentd = new Sentd('your_api_key'); // Send an email $result = $sentd->emails->send([ 'from' => 'hello@yourdomain.com', 'to' => 'user@example.com', 'subject' => 'Welcome!', 'html' => '<h1>Hello World</h1>', ]); echo "Email sent! ID: " . $result['data']['id'];
Features
- Emails - Send, list, get, cancel, reschedule, and resend emails
- Batch - Send bulk emails efficiently
- Templates - Create and manage email templates
- Domains - Add and verify sending domains
- Webhooks - Configure webhook endpoints
- Analytics - Get email statistics
API Reference
Emails
// Send an email $result = $sentd->emails->send([ 'from' => 'hello@yourdomain.com', 'to' => 'user@example.com', 'subject' => 'Hello', 'html' => '<h1>World</h1>', ]); // Send to multiple recipients $result = $sentd->emails->send([ 'from' => 'hello@yourdomain.com', 'to' => ['user1@example.com', 'user2@example.com'], 'subject' => 'Hello', 'html' => '<h1>World</h1>', ]); // List emails $emails = $sentd->emails->list([ 'limit' => 10, 'status' => 'delivered', ]); // Get an email $email = $sentd->emails->get('email_id'); // Cancel a scheduled email $sentd->emails->cancel('email_id'); // Resend a failed email $sentd->emails->resend('email_id');
Batch
// Send batch emails $result = $sentd->batch->send([ 'from' => 'hello@yourdomain.com', 'subject' => 'Newsletter', 'html' => '<h1>Hello {{name}}</h1>', 'emails' => [ ['to' => 'user1@example.com', 'data' => ['name' => 'Alice']], ['to' => 'user2@example.com', 'data' => ['name' => 'Bob']], ], ]);
Templates
// Create a template $template = $sentd->templates->create([ 'name' => 'Welcome Email', 'subject_template' => 'Welcome, {{name}}!', 'html_template' => '<h1>Hello {{name}}</h1>', ]); // List templates $templates = $sentd->templates->list(); // Preview a template $preview = $sentd->templates->preview('template_id', ['name' => 'John']);
Domains
// Add a domain $domain = $sentd->domains->add('yourdomain.com'); // List domains $domains = $sentd->domains->list(); // Verify a domain $result = $sentd->domains->verify('domain_id');
Webhooks
// Create a webhook $webhook = $sentd->webhooks->create([ 'url' => 'https://yourdomain.com/webhooks', 'events' => ['email.delivered', 'email.bounced'], ]); // Test a webhook $result = $sentd->webhooks->test('webhook_id');
Analytics
// Get analytics $analytics = $sentd->analytics->get([ 'days' => 30, 'group_by' => 'day', ]); // Export as CSV $csv = $sentd->analytics->exportCsv(30);
Configuration
// Custom configuration $sentd = new Sentd('your_api_key', [ 'base_url' => 'https://custom.api.sentd.io', 'timeout' => 60, ]);
Error Handling
use Sentd\Exception\AuthenticationException; use Sentd\Exception\RateLimitException; use Sentd\Exception\ValidationException; use Sentd\Exception\NotFoundException; use Sentd\Exception\ApiException; try { $result = $sentd->emails->send($params); } catch (AuthenticationException $e) { echo "Invalid API key"; } catch (RateLimitException $e) { echo "Rate limited, please retry later"; } catch (ValidationException $e) { echo "Validation error: " . $e->getMessage(); print_r($e->getDetails()); } catch (NotFoundException $e) { echo "Resource not found"; } catch (ApiException $e) { echo "API error: " . $e->getMessage(); }
License
MIT License - see LICENSE for details.