Official PHP client for the SENTD Email API.
- PHP 8.1 or higher
- Composer
composer require sentd/sentd-php<?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'];- 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
// 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');// 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']],
],
]);// 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']);// Add a domain
$domain = $sentd->domains->add('yourdomain.com');
// List domains
$domains = $sentd->domains->list();
// Verify a domain
$result = $sentd->domains->verify('domain_id');// 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');// Get analytics
$analytics = $sentd->analytics->get([
'days' => 30,
'group_by' => 'day',
]);
// Export as CSV
$csv = $sentd->analytics->exportCsv(30);// Custom configuration
$sentd = new Sentd('your_api_key', [
'base_url' => 'https://custom.api.sentd.io',
'timeout' => 60,
]);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();
}MIT License - see LICENSE for details.