How to send emails with WordPress

Call Publiq from a plugin or your theme `functions.php` with `wp_remote_post` (built into WordPress).

Define the key (e.g. define('PUBLIQ_API_KEY', 'pk_...') in wp-config.php) and send:

<?php
function send_welcome_email($email) {
    wp_remote_post('https://api.publiq.digital/v1/emails', [
        'headers' => [
            'Authorization' => 'Bearer ' . PUBLIQ_API_KEY,
            'Content-Type'  => 'application/json',
        ],
        'body' => wp_json_encode([
            'from' => 'you@yourdomain.com',
            'to' => $email,
            'templateKey' => 'welcome-email',
        ]),
    ]);
}

Best practices

  • Always call Publiq from the server — the API key goes in the Authorization header, never on the client.
  • On 429/5xx, retry with exponential backoff (respect Retry-After).
  • Prefer templateKey over inline HTML to keep content versioned.
  • Handle errors via the response error.code field — see Errors.
  • Send from a verified domain — see Domains.

See also

How to send emails with WordPress — Publiq Docs