PHP
Official PHP SDK for Keplars
Installation
Install the package
composer require keplars/email-sdkSet your API key
KEPLARS_API_KEY=kms_your_workspace_id.live_your_secretSend your first email
<?php
require 'vendor/autoload.php';
use Keplars\Email\Client;
$client = new Client($_ENV['KEPLARS_API_KEY']);
$response = $client->emails->sendInstant([
'to' => '[email protected]',
'from' => '[email protected]',
'subject' => 'Hello!',
'body' => '<h1>It works!</h1>',
'is_html' => true,
]);
echo $response['id'];Priority Levels
| Method | Delivery | Use case |
|---|---|---|
sendInstant | 0–5 seconds | OTP, 2FA, password reset |
sendHigh | 0–30 seconds | Transactional confirmations |
sendAsync / send | 0–5 minutes | Welcome emails, notifications |
sendBulk | Background | Newsletters, campaigns |
$client->emails->sendInstant([...]);
$client->emails->sendHigh([...]);
$client->emails->sendAsync([...]);
$client->emails->sendBulk([...]);Using Templates
$response = $client->emails->sendInstant([
'to' => '[email protected]',
'from' => '[email protected]',
'template_id' => 'your-template-id',
'params' => [
'user_name' => 'Jane',
'verification_code' => '123456',
],
]);Schedule an Email
$response = $client->emails->schedule([
'to' => '[email protected]',
'from' => '[email protected]',
'subject' => 'Weekly digest',
'body' => '<p>Here is your digest.</p>',
'is_html' => true,
'scheduled_for' => '2026-02-01T09:00:00Z',
'timezone' => 'America/New_York',
]);Error Handling
use Keplars\Email\Exceptions\AuthenticationException;
use Keplars\Email\Exceptions\RateLimitException;
use Keplars\Email\Exceptions\ValidationException;
try {
$response = $client->emails->sendInstant([...]);
} catch (AuthenticationException $e) {
echo 'Invalid API key';
} catch (RateLimitException $e) {
echo 'Rate limit hit, retry after: ' . $e->getRetryAfter();
} catch (ValidationException $e) {
echo 'Validation error: ' . $e->getMessage();
}Laravel Integration
// config/services.php
'keplars' => [
'api_key' => env('KEPLARS_API_KEY'),
],
// In your service or controller
$client = new \Keplars\Email\Client(config('services.keplars.api_key'));Admin API
Need to manage contacts, audiences, automations, or domains? Use an admin key - same client, different key suffix:
$client = new Client('kms_xxx.adm_xxx');
$client->contacts->add(['email' => '[email protected]', 'name' => 'Jane']);
$client->audiences->create('Newsletter');
$client->automations->enroll('auto_id', '[email protected]');
$client->domains->verify('domain_id');See the full Admin API reference.
Next Steps
- Admin API - Contacts, audiences, automations, domains
- Send Emails - API reference
- Email Templates - Build reusable templates
- Schedule Emails - Delayed delivery