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();

Override brand

php
$client->event('welcome')
    ->to('user@example.com')
    ->overrides([
        'brand' => ['logotype' => 'https://example.fi/logo.png']
    ])
    ->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, push, telegram, whatsapp, discord)
contacts()Access the Contacts API
language($code)Set language code
overrides($array)Override template settings
idempotencyKey($key)Prevent duplicate sends
send()Send synchronously
sendAsync()Send asynchronously

Contacts

Manage contacts and push tokens via the contacts() method.

Upsert a contact

php
$client->contacts()->upsert([
    'id' => 'user-123',
    'name' => 'Alice',
    'email' => 'alice@example.com',
    'push_token' => 'ExponentPushToken[...]'
]);

Get a contact

php
$result = $client->contacts()->get('user-123');
print_r($result['contact']['pushTokens']); // ['ExponentPushToken[...]']

Register push token

Additive — doesn't remove existing tokens. Call on app startup.

php
$client->contacts()->registerPushToken('user-123', $expoPushToken);

Remove push token

Call on logout to stop sending to this device.

php
$client->contacts()->removePushToken('user-123', $expoPushToken);

Update a contact

php
$client->contacts()->update('user-123', ['name' => 'Alice Updated']);

Delete a contact

Hard delete (GDPR compliance).

php
$client->contacts()->delete('user-123');

Contact methods

MethodDescription
contacts()->get($id)Get contact by any identifier
contacts()->upsert($data)Create or update contact
contacts()->update($id, $data)Update existing contact
contacts()->delete($id)Hard delete (GDPR)
contacts()->registerPushToken($id, $token)Register device token (additive)
contacts()->removePushToken($id, $token)Remove device token

See Push Notifications for the full push setup guide.

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.