How to Use Notify with PHP
Send email with PHP and cURL.
Send email from PHP using cURL.
Prerequisites
- API key — authenticate every request with the
x-api-keyheader - Verified domain (optional) — required for production sends from a custom
fromaddress - PHP with the cURL extension enabled
Send an email
<?php
$payload = [
'to' => 'user@example.com',
'subject' => 'Welcome aboard!',
'message' => '<h1>Welcome!</h1><p>Thanks for joining us.</p>',
];
$ch = curl_init('https://notify.cx/api/public/v1/email/send');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Content-Type: application/json',
'x-api-key: ' . getenv('NOTIFY_API_KEY'),
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$response = curl_exec($ch);
if ($response === false) {
throw new RuntimeException('Request failed: ' . curl_error($ch));
}
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($status < 200 || $status >= 300) {
throw new RuntimeException("Notify error ($status): $response");
}
echo $response;
API response:
{
"success": true,
"data": {
"messageId": "01000194b1dd1c04-b51e7343-6808-4a68-b2af-845feae57f8b-000000"
}
}
Plain text message
Use a plain string in message when you do not need HTML:
$payload = [
'to' => 'user@example.com',
'subject' => 'Welcome aboard!',
'message' => 'Thanks for joining us!',
];
See Sending Emails for what gets delivered for each format.