Skip to content

PHP SDK

Install

bash
composer require sendivent/sdk

Requires PHP 8.1+ and Guzzle 7.0+.

Quickstart

php
use Sendivent\Sendivent;

$client = new Sendivent(getenv('SENDIVENT_API_KEY'));

$response = $client
    ->event('welcome')
    ->to('user@example.com')
    ->payload(['name' => 'Alice'])
    ->send();

if (!$response->isSuccess()) {
    echo $response->error;
}

Configuration

Set SENDIVENT_API_KEY in your environment. The SDK automatically routes requests to the correct API based on your key prefix: test_ → sandbox, live_ → production. See Sandbox vs Production.

Common tasks

Send with payload

php
$client->event('order-shipped')
    ->to('user@example.com')
    ->payload(['order_id' => '12345', 'tracking_url' => 'https://...'])
    ->send();

Send to a contact object

php
$client->event('welcome')
    ->to([
        'email' => 'user@example.com',
        'name' => 'Alice',
        'id' => 'user_123',
        'plan' => 'premium'
    ])
    ->send();

See Contacts for identifier rules and meta fields.

Force a channel

php
$client->event('verification')
    ->channel('sms')
    ->to('+46701234567')
    ->send();

See Routing.

Set language

php
$client->event('welcome')
    ->language('sv')
    ->to('anders@example.com')
    ->send();

See Templates for language variants.

Send to multiple recipients

php
$client->event('newsletter')
    ->to(['user1@example.com', 'user2@example.com'])
    ->payload(['subject' => 'Monthly Update'])
    ->send();

Override template settings

php
$client->event('invoice')
    ->to('user@example.com')
    ->overrides([
        'email' => [
            'subject' => 'Your Invoice',
            'reply_to' => 'billing@yourcompany.com'
        ]
    ])
    ->send();

Prevent duplicates

php
$client->event('order-confirmation')
    ->to('user@example.com')
    ->idempotencyKey('order-12345')
    ->send();

Fire-and-forget

Use sendAsync() to send without waiting for a response. The request is sent immediately and your code continues — no blocking.

php
$client->event('welcome')
    ->to('user@example.com')
    ->sendAsync();

// Code continues immediately, notification sends in background

Ideal for non-critical notifications where you don't need delivery confirmation.

Response and delivery tracking

send() returns a response object. On success, it includes delivery identifiers you can look up in the dashboard Activity log.

php
$response = $client->event('welcome')->to('user@example.com')->send();
if ($response->isSuccess()) print_r($response->data);

See Send API for the full response format.

Error handling

php
$response = $client->event('welcome')->to('user@example.com')->send();

if ($response->isSuccess()) {
    print_r($response->data);
} else {
    echo "Error: " . $response->error;
}

Methods

MethodDescription
event($name)Set event name
to($recipient)Set recipient(s)
from($sender)Set custom sender (verified)
payload($data)Set template data
channel($name)Force channel (email, sms, slack)
language($code)Set language code
overrides($array)Override template settings
idempotencyKey($key)Prevent duplicate sends
send()Send synchronously
sendAsync()Send asynchronously

Common pitfalls

  • Using test_ key in production — lower rate limits and separate database (see Sandbox)
  • Forcing sms without a phone number — send fails (see Routing)
  • Blank template variables — you didn't send required payload/meta fields (see Templates)

See also

Released under the MIT License.