![]() |
|
Guide How to Use the BillionMail Send API for Transactional Email (With curl and PHP) - Printable Version +- AdminsForum (https://adminsforum.com) +-- Forum: Free & open-source control panels (https://adminsforum.com/Forum-free-open-source-control-panels) +--- Forum: aaPanel (https://adminsforum.com/Forum-aapanel) +---- Forum: aaPanel Guides & Tutorials (https://adminsforum.com/Forum-aapanel-guides-tutorials) +----- Forum: aaPanel BillionMail Guides (https://adminsforum.com/Forum-aapanel-billionmail-guides) +----- Thread: Guide How to Use the BillionMail Send API for Transactional Email (With curl and PHP) (/Thread-guide-how-to-use-the-billionmail-send-api-for-transactional-email-with-curl-and-php) |
How to Use the BillionMail Send API for Transactional Email (With curl and PHP) - JAY - 10-23-2026 How to Use the BillionMail Send API for Transactional Email (With curl and PHP) Newsletters are only half of what most sites send. The other half is transactional email: password resets, order receipts, sign-up confirmations and login codes. These go to one person, right now, because they did something. BillionMail has a built-in Send API for exactly this, so your app or website can send through your own mail server instead of a paid service. This guide shows how to create an API, call it with curl and PHP, and put personal values like a name or a code into the email. Before you start
Step 1: Create the API Open Send API in the left menu and click Create API. The form looks like this: Fill it in like this:
IP Whitelist is worth filling in: enter your app server's IP address (several are separated by commas). Then the key only works from that server, even if it leaks. Empty means any IP can use it. After you save, the API appears in the list with its API Key, plus send count and open, click and bounce rates. Step 2: Send a test with curl The endpoint is Code: /api/batch_mail/api/sendCode: curl -X POST 'https://mail.example.com/api/batch_mail/api/send' \
-H 'X-API-Key: YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{"recipient":"[email protected]"}'Code: "success":trueCode: "code":0Code: -kStep 3: Put personal values in the email Most transactional emails need something personal: a name, a reset link, a code. Send them in Code: attribsCode: {"recipient":"[email protected]",
"attribs":{"name":"Jane","code":"482913","link":"https://example.com/reset?t=abc"}}Code: {{.API.name}}Code: {{.API.code}}Code: <p>Hi {{.API.name}},</p>
<p>Your login code is <b>{{.API.code}}</b>. It expires in 10 minutes.</p>Code: codeCode: {{.API.code}}Code: {{.API.Code}}Step 4: Call it from PHP Code: <?php
function send_mail($to, array $vars) {
$ch = curl_init('https://mail.example.com/api/batch_mail/api/send');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 15,
CURLOPT_HTTPHEADER => ['X-API-Key: ' . getenv('BM_API_KEY'), 'Content-Type: application/json'],
CURLOPT_POSTFIELDS => json_encode(['recipient' => $to, 'attribs' => $vars]),
]);
$res = json_decode(curl_exec($ch), true);
curl_close($ch);
return !empty($res['success']);
}
send_mail('[email protected]', ['name' => 'Jane', 'code' => '482913']);Sending to several people For a small list, use Code: /api/batch_mail/api/batch_sendCode: "recipients":["[email protected]","[email protected]"]Code: recipientIf it doesn't work
More BillionMail guides
Applies to BillionMail 4.9, October 2026. Replace Code: example.comCode: mail.example.com |