How to send emails with Laravel

Use Laravel's HTTP Client (the `Http` facade) to call the Publiq API — no SDK. Set `PUBLIQ_API_KEY` in `.env`.

Direct call with the Http facade:

<?php
use Illuminate\Support\Facades\Http;

$response = Http::withToken(env('PUBLIQ_API_KEY'))
    ->post('https://api.publiq.digital/v1/emails', [
        'from' => 'you@yourdomain.com',
        'to' => $user->email,
        'templateKey' => 'welcome-email',
        'variables' => ['first_name' => $user->name],
    ]);

return $response->json();

Wrap it in a service class (app/Services/Publiq.php) and inject it where needed, keeping the call in one place.

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 Laravel — Publiq Docs