1. Go to this page and download the library: Download sendpigeon/sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sendpigeon / sdk example snippets
use SendPigeon\SendPigeon;
$client = new SendPigeon('sk_live_xxx');
$response = $client->send(
to: '[email protected]',
subject: 'Hello',
html: '<p>Welcome to SendPigeon!</p>'
);
echo "Email sent: " . $response->id;
$client = new SendPigeon(
apiKey: 'sk_live_xxx',
baseUrl: 'https://api.sendpigeon.dev', // Custom base URL
timeout: 30, // Request timeout in seconds
maxRetries: 2, // Retry attempts (max 5)
);
$response = $client->send(
to: '[email protected]',
from: '[email protected]',
subject: 'Welcome!',
html: '<h1>Welcome</h1><p>Thanks for signing up!</p>',
text: 'Welcome! Thanks for signing up.',
);
// Add domain
$domain = $client->domains->create('mail.yourdomain.com');
// DNS records are returned for setup
foreach ($domain->dnsRecords as $record) {
echo "{$record->type} {$record->name} -> {$record->value}\n";
}
// Verify domain
$result = $client->domains->verify('dom_xxx');
if ($result->verified) {
echo "Domain verified!\n";
}
// List domains
$result = $client->domains->list();
// Delete domain
$client->domains->delete('dom_xxx');
use SendPigeon\Types\ApiKeyMode;
use SendPigeon\Types\ApiKeyPermission;
// Create API key
$key = $client->apiKeys->create(
name: 'Production',
mode: ApiKeyMode::Live,
permission: ApiKeyPermission::FullAccess,
);
// Save $key->key - only returned once!
echo "API Key: " . $key->key;
// List API keys
$result = $client->apiKeys->list();
// Delete API key
$client->apiKeys->delete('key_xxx');
use SendPigeon\Webhooks;
// In your webhook handler
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? '';
$timestamp = $_SERVER['HTTP_X_WEBHOOK_TIMESTAMP'] ?? '';
$result = Webhooks::verify(
payload: $payload,
signature: $signature,
timestamp: $timestamp,
secret: 'whsec_xxx', // Your webhook secret
maxAge: 300, // Max age in seconds
);
if (!$result->valid) {
http_response_code(401);
echo $result->error;
exit;
}
// Handle webhook event
$eventType = $result->payload['type'];
switch ($eventType) {
case 'email.delivered':
// Handle delivery
break;
case 'email.bounced':
// Handle bounce
break;
}
http_response_code(200);
$response = $client->send(
to: '[email protected]',
subject: 'Order confirmation',
html: '<p>Your order has been confirmed.</p>',
idempotencyKey: 'order-12345-confirmation',
);
bash
# Terminal 1: Start local server
npx @sendpigeon-sdk/cli dev
# Terminal 2: Run your app with dev mode
SENDPIGEON_DEV=true php app.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.