Search by

senviok / senviok-php

chekwube

Official PHP SDK for the Senviok API

v1.0.0 2026-08-19 13:36 UTC

This package is auto-updated.

Last update: 2026-11-19 23:57:11 UTC


README

The official PHP SDK for the Senviok notification and messaging infrastructure API.

Installation

You can install the SDK via Composer:

composer require senviok/senviok-php

Make sure you have GuzeHttp installed (Composer will automatically attempt to install Guzzle 7 when installing this package).

Quick Start

1. Initialize Client

require_once 'vendor/autoload.php';

use Senviok\Senviok;

// Initialize client with your API key
$senviok = new Senviok('svk_live_your_api_key_here');

2. Send an Email

try {
    $response = $senviok->emails->send([
        'from' => 'Sender Name <onboarding@senviok.live>',
        'to' => 'user@example.com',
        'subject' => 'Welcome to Senviok!',
        'html' => '<h1>Hello World</h1><p>This is a transactional email.</p>'
    ]);

    echo "Email Sent! ID: " . $response['id'] . "\n";
} catch (\Senviok\Exceptions\ApiException $e) {
    echo "Error (" . $e->getStatusCode() . "): " . $e->getMessage() . "\n";
}

API Documentation

Emails & Inbox

// Send email with attachments
$senviok->emails->send([
    'from' => 'verify@yourdomain.com',
    'to' => 'recipient@example.com',
    'subject' => 'Monthly Report',
    'html' => '<p>Attached is your invoice.</p>',
    'attachments' => [
        [
            'filename' => 'invoice.pdf',
            'contentType' => 'application/pdf',
            'content' => base64_encode(file_get_contents('invoice.pdf'))
        ]
    ]
]);

// List incoming emails in your inbox
$inbox = $senviok->emails->listInbox([
    'limit' => 20,
    'offset' => 0
]);

// Get incoming email details
$email = $senviok->emails->getInbox('inbound_msg_id');

// Reply to an incoming thread
$senviok->emails->replyInbox('inbound_msg_id', [
    'textBody' => 'Hi, thanks for reaching out. We received your request.'
]);

Each attachment must provide exactly one of content (base64 file bytes) or path (a public HTTPS URL). Optional fields are contentType and contentId (for inline CID images). For larger files, upload multipart field file to POST /v1/emails/attachments and pass the returned IDs in attachmentIds. The API allows up to 10 files and 10 MB total per email.

The PHP SDK has a helper for the upload flow:

$upload = $senviok->emails->uploadAttachment(
    'invoice.pdf', file_get_contents('invoice.pdf'), 'application/pdf'
);
$senviok->emails->send([
    'from' => 'billing@example.com', 'to' => 'customer@example.com',
    'subject' => 'Your invoice', 'attachmentIds' => [$upload['id']],
]);

SMS

$senviok->sms->send([
    'from' => 'SVKALERT',
    'to' => '+2348012345678',
    'sms' => 'Your OTP code is 981249. Expires in 5 minutes.'
]);

WhatsApp

$senviok->whatsapp->send([
    'from' => '+2348012345678', // Sender number
    'to' => '+2348087654321',   // Recipient
    'text' => 'Your order #28103 has been shipped!'
]);

OTP Verification

// Send OTP
$otp = $senviok->otp->send([
    'to' => '+2348012345678',
    'from' => 'SVKALERT',
    'channel' => 'SMS',
    'expiryMinutes' => 5
]);

// Resend OTP (keeps the same code if still valid to reduce spam/costs)
$resend = $senviok->otp->resend([
    'to' => '+2348012345678',
    'from' => 'SVKALERT',
    'channel' => 'SMS'
]);

// Verify OTP
$verification = $senviok->otp->verify([
    'to' => '+2348012345678',
    'code' => '123456'
]);

Templates CRUD

// Create
$template = $senviok->templates->create([
    'name' => 'Verify Account',
    'subject' => 'Verification Code: {{code}}',
    'htmlContent' => '<p>Use code <b>{{code}}</b> to complete signup.</p>'
]);

// Update
$senviok->templates->update('tmpl_id', [
    'name' => 'Updated Name'
]);

// Delete
$senviok->templates->delete('tmpl_id');

Custom Domains

// Register domain
$domain = $senviok->domains->create(['name' => 'mydomain.com']);

// Get DKIM keys
$dkim = $senviok->domains->getDkim('dom_id');

// Verify DNS records
$result = $senviok->domains->verify('dom_id');

Webhook Signature Verification

To verify that webhook requests coming into your application are sent by Senviok, use the signature verification utility:

$rawBody = file_get_contents('php://input');
$signature = $_SERVER['HTTP_SVK_SIGNATURE'] ?? '';
$secret = 'whsec_your_webhook_secret_here';

$isValid = $senviok->webhooks->verifySignature($rawBody, $signature, $secret);

if ($isValid) {
    // Process event safely
} else {
    // Reject request
    http_response_code(401);
}

License

MIT License.