The official PHP SDK for FlySend — send transactional emails through the FlySend API.
Works with any PHP project. No framework dependencies.
- PHP 8.2+
- cURL extension
composer require flysend/flysend-phpuse FlySend\FlySend;
$flysend = new FlySend('your-api-key');
$response = $flysend->emails->send([
'from' => 'hello@example.com',
'to' => 'user@example.com',
'subject' => 'Welcome!',
'html' => '<p>Hello world!</p>',
]);
echo $response['data']['id']; // email ID$flysend = new FlySend(
apiKey: 'your-api-key',
baseUrl: 'https://api.flysend.co', // optional, for self-hosted instances
timeout: 30, // optional, default 30s
);$response = $flysend->emails->send([
'from' => 'Company <hello@example.com>',
'to' => 'user@example.com',
'subject' => 'Welcome!',
'html' => '<p>Hello!</p>',
'text' => 'Hello!', // optional
'cc' => 'cc@example.com', // optional
'bcc' => 'bcc@example.com', // optional
'reply_to' => 'support@example.com', // optional
'tags' => [ // optional
['name' => 'campaign', 'value' => 'welcome'],
],
'attachments' => [ // optional
[
'filename' => 'invoice.pdf',
'content' => base64_encode($pdfContent),
'mime_type' => 'application/pdf',
],
],
]);
echo $response['data']['id']; // email IDSend up to 100 emails in a single request:
$response = $flysend->emails->batch([
[
'from' => 'hello@example.com',
'to' => 'user1@example.com',
'subject' => 'Hello User 1',
'html' => '<p>Hi!</p>',
],
[
'from' => 'hello@example.com',
'to' => 'user2@example.com',
'subject' => 'Hello User 2',
'html' => '<p>Hi!</p>',
],
]);
echo $response['queued_count']; // number of emails queued
echo $response['error_count']; // number of failuresuse FlySend\Exceptions\FlySendException;
use FlySend\Exceptions\QuotaExceededException;
use FlySend\Exceptions\ValidationException;
try {
$flysend->emails->send([...]);
} catch (QuotaExceededException $e) {
echo 'Quota exceeded. Remaining: ' . $e->quota['remaining'];
echo 'Resets at: ' . $e->quota['resets_at'];
} catch (ValidationException $e) {
echo 'Validation errors: ';
print_r($e->errors); // ['field' => ['error message', ...]]
} catch (FlySendException $e) {
echo 'API error: ' . $e->getMessage();
echo 'Status code: ' . $e->getStatusCode();
}MIT