How to send emails with PHP
There is no official PHP SDK — call the Publiq REST API with Guzzle (or cURL). Send from the server with the API key in the header.
With Guzzle (composer require guzzlehttp/guzzle):
<?php
use GuzzleHttp\Client;
$client = new Client();
$res = $client->post('https://api.publiq.digital/v1/emails', [
'headers' => ['Authorization' => 'Bearer ' . getenv('PUBLIQ_API_KEY')],
'json' => [
'from' => 'you@yourdomain.com',
'to' => 'user@example.com',
'templateKey' => 'welcome-email',
'variables' => ['first_name' => 'Ana'],
],
]);
$email = json_decode($res->getBody(), true);
echo $email['id'];Best practices
- Always call Publiq from the server — the API key goes in the
Authorizationheader, never on the client. - On
429/5xx, retry with exponential backoff (respectRetry-After). - Prefer
templateKeyover inline HTML to keep content versioned. - Handle errors via the response
error.codefield — see Errors. - Send from a verified domain — see Domains.