PHP & Laravel SDK
Official PHP SDK for the Sendry email API, with first-class Laravel support.
Installation
composer require sendry/sendry
Requires PHP 8.1+. Works in plain PHP, Symfony, and Laravel 10/11/12.
Standalone PHP
use Sendry\Sendry;
$sendry = new Sendry(getenv('SENDRY_API_KEY'));
$response = $sendry->emails->send([
'from' => 'hello@yourdomain.com',
'to' => 'user@example.com',
'subject' => 'Welcome',
'html' => '<p>Thanks for signing up.</p>',
'text' => 'Thanks for signing up.',
]);
echo $response['id'];
Laravel
The package ships with a service provider auto-discovered by Laravel and a facade.
1. Publish the config
php artisan vendor:publish --tag=sendry-config
This creates config/sendry.php:
return [
'api_key' => env('SENDRY_API_KEY'),
'base_url' => env('SENDRY_BASE_URL', 'https://api.sendry.online'),
'timeout' => env('SENDRY_TIMEOUT', 30),
'retries' => env('SENDRY_RETRIES', 2),
];
2. Add credentials to .env
SENDRY_API_KEY=sn_live_your_api_key_here
3. Send via facade
use Sendry\Laravel\Facades\Sendry;
Sendry::emails()->send([
'from' => 'hello@yourdomain.com',
'to' => $user->email,
'subject' => 'Welcome, '.$user->name,
'html' => view('emails.welcome', ['user' => $user])->render(),
]);
4. Or resolve from the container
use Sendry\Sendry;
public function handle(Sendry $sendry)
{
$sendry->emails->send([...]);
}
Mail driver
The package ships an official Symfony Mailer transport
(Sendry\Symfony\SendryTransport) and the Laravel service provider auto-registers
it. To route Laravel's Mail facade through Sendry, add a mailer in
config/mail.php:
'mailers' => [
'sendry' => [
'transport' => 'sendry',
],
],
Then in .env:
MAIL_MAILER=sendry
MAIL_FROM_ADDRESS="hello@your-verified-domain.com"
MAIL_FROM_ADDRESS must use a domain you've verified in Sendry. Send normally:
Mail::to($user)->send(new WelcomeMail($user));
Plain Symfony (without Laravel)
Wire the factory into your transport chain and use the sendry:// DSN:
use Sendry\Symfony\SendryTransportFactory;
use Symfony\Component\Mailer\Transport;
$transport = Transport::fromDsn('sendry://sn_live_xxx@default', null, null, [
new SendryTransportFactory(),
]);
Requires symfony/mailer ^6.4 || ^7.0 (Laravel apps already ship it).
Resources
All resources mirror the REST API:
$sendry->emails // send, sendBatch, get, list
$sendry->domains // create, verify, list, delete
$sendry->templates // create, update, get, list, delete
$sendry->contacts // upsert, get, list, delete
$sendry->audiences // create, list, delete
$sendry->campaigns // create, send, get, list
$sendry->webhooks // create, list, delete, verifySignature()
$sendry->analytics // overview, breakdown, cohort, benchmark
$sendry->suppression // add, check, remove, list
$sendry->unsubscribes // list
$sendry->apiKeys // create, list, delete
$sendry->team // invite, list, updateRole, remove
$sendry->billing // overview, createCheckout, createPortal
Error handling
All API errors throw subclasses of Sendry\Exceptions\SendryException:
use Sendry\Exceptions\{
SendryException,
AuthenticationException,
ValidationException,
RateLimitException,
NotFoundException,
ApiException,
};
try {
$sendry->emails->send([...]);
} catch (RateLimitException $e) {
sleep($e->retryAfter ?? 1);
// ...retry
} catch (ValidationException $e) {
Log::warning('Sendry validation failed', $e->details);
} catch (SendryException $e) {
report($e);
}
Webhook signature verification
use Sendry\Laravel\Facades\Sendry;
Route::post('/webhooks/sendry', function (Request $request) {
$valid = Sendry::verifyWebhookSignature(
$request->getContent(),
$request->header('X-Sendry-Signature'),
config('services.sendry.webhook_secret'),
);
abort_unless($valid, 401);
// Process event...
});
Source
github.com/sendry-dev/sendry-php — Apache-2.0 licensed.