PHP
Send an email from PHP with the usenotix/notix-php package.
Send your first email from PHP with usenotix/notix-php, the official SDK. It needs PHP 8.1 or newer with the curl and json extensions. Using Laravel? Follow the Laravel quickstart instead.
Prerequisites
- An API key.
- A verified domain to send from.
Install the SDK
composer require usenotix/notix-phpSet your API key
Keep the key in your environment, not in your code.
NOTIX_API_KEY=notix_12345Send an email
<?php require __DIR__ . '/vendor/autoload.php'; use Notix\Notix; $notix = new Notix(getenv('NOTIX_API_KEY')); $email = $notix->emails->send([ 'from' => 'Acme <receipts@acme.com>', 'to' => 'maria@example.com', 'subject' => 'Your receipt for order 4471', 'html' => '<p>Thanks for your order, Maria.</p>', 'text' => 'Thanks for your order, Maria.', ]); echo $email['emailId'];Handle errors
The SDK throws when the API answers with an error. Every exception extends
Notix\Exception\NotixException, with a class per error, such asUnauthorizedExceptionandRateLimitedException.use Notix\Exception\NotixException; try { $email = $notix->emails->send([ 'from' => 'receipts@acme.com', 'to' => 'maria@example.com', 'subject' => 'Your receipt', 'html' => '<p>Thanks for your order.</p>', ]); } catch (NotixException $e) { echo $e->getHttpStatus() . ' ' . $e->getErrorCode() . ': ' . $e->getMessage(); }
Next steps
- Send many emails at once with batch sending:
$notix->emails->batch([...]). - Add files with attachments.
- Make retries safe with idempotency keys. Pass the key as the second argument:
$notix->emails->send($payload, 'order-4471-receipt'). - Hear about deliveries and bounces with webhooks.