Send with PHP
Send email from PHP with the usend SDK, over plain HTTP or over SMTP.
The official PHP SDK has no dependencies and needs PHP 8.1 or newer (ext-curl is used when present). You need a verified domain and an API key.
1. Install and set the key
composer require usend/usend
export USEND_API_KEY="us_123456789"2. Send
<?php
require 'vendor/autoload.php';
$usend = new Usend\Client(getenv('USEND_API_KEY'));
try {
$email = $usend->emails->send([
'from' => 'Acme <[email protected]>',
'to' => ['[email protected]'],
'subject' => 'Hello from usend',
'html' => '<p>It works!</p>',
], 'welcome-ann-1'); // optional idempotency key
echo "queued {$email['id']}\n";
} catch (Usend\UsendException $e) {
fwrite(STDERR, "{$e->getStatusCode()} {$e->getErrorName()}: {$e->getMessage()}\n");
exit(1);
}php send.phpA failure throws Usend\UsendException with the status code, the error name and the message; see Errors. Rate limits and server errors are retried automatically, and the idempotency key makes a retry safe: see Idempotency.
Webhooks
$event = Usend\Webhook::verify(file_get_contents('php://input'), getallheaders(), getenv('USEND_WEBHOOK_SECRET'));It throws Usend\UsendException when the signature is wrong. See Verify signatures.
Without the SDK
The API is one JSON request: POST https://api.usend.et/emails with an Authorization: Bearer header works from cURL, Guzzle or Symfony HttpClient. If your app already uses PHPMailer or mail() through an MTA, point it at usend over SMTP instead (see PHPMailer): host smtp.usend.et, port 465 or 587, username usend, your API key as the password. $usend->smtpConfig() returns these settings.
Next steps
- Send emails for every field.
- Attachments: base64-encode the file in
content.