noburi / send-php
PHP client for the Noburi Send transactional email API.
Requires
- php: ^8.2
- ext-json: *
- guzzlehttp/guzzle: ^7.8 || ^8.0
Requires (Dev)
- pestphp/pest: ^3.0 || ^4.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
PHP client for the Noburi Send transactional email API.
Using Laravel? Install noburi/send-laravel instead: it brings this client, a mail transport and webhook events.
Install
composer require noburi/send-php
Requires PHP 8.2 or later.
Send an email
$noburi = Noburi\Send\NoburiSend::client('ps_live_xxxxxxxxx'); $email = $noburi->emails->send([ 'from' => 'Acme <hello@acme.com>', 'to' => ['jane@example.com'], 'subject' => 'Your login code', 'html' => '<p>Your code is <strong>123456</strong></p>', ], ['idempotency_key' => 'otp-42']); echo $email['id']; // em_...
Every part of the API is a property, or a method of the same name:
| Service | Calls |
|---|---|
emails |
send, batch, get, list, update, reschedule, cancel |
domains |
create, list, get, update, verify, remove |
webhooks |
create, list, get, update, rotateSecret, test, remove |
templates |
create, list, get, update, remove, publish, render, versions |
Answers are the API's JSON, decoded into arrays.
Errors
An API error throws a subclass of Noburi\Send\Exception\ApiException, with the fields of the error object:
use Noburi\Send\Exception\ValidationException; try { $noburi->emails->send([...]); } catch (ValidationException $e) { $e->errorCode; // domain_not_verified $e->param; // from $e->docUrl; // link to the error's documentation }
AuthenticationException, PermissionException, NotFoundException, ValidationException, InsufficientCreditsException, IdempotencyException and RateLimitException (with retryAfter) follow the error's type. A network failure throws ApiConnectionException.
Webhooks
use Noburi\Send\Webhook; $event = Webhook::constructEvent( file_get_contents('php://input'), $_SERVER['HTTP_X_PULSESEND_SIGNATURE'] ?? null, 'your_webhook_secret', );
It throws SignatureVerificationException when the signature is missing, wrong or older than five minutes.
Options
Noburi\Send\NoburiSend::client('ps_live_...', [ 'base_url' => 'https://send.noburi.space', 'timeout' => 30, ]);
License
MIT
Moving from pulsesend/pulsesend-php
Same code, new name: composer remove pulsesend/pulsesend-php && composer require noburi/send-php, then replace PulseSend\ with Noburi\Send\ in your imports and PulseSend::client(...) with NoburiSend::client(...). The API and your keys do not change.