Send email from Laravel with an email API
Send email from Laravel with the Http facade instead of an SMTP mailer: one POST, an id back, and every delivery event on a webhook.
<?php// config/services.php:// 'rasket' => ['key' => env('RASKET_API_KEY')]// Read it through config(), never env() directly:// a cached config makes env() return null.
use Illuminate\Support\Facades\Http;
$key = config('services.rasket.key');
$response = Http::withToken($key) ->withHeaders([ // Required on every request. 'User-Agent' => 'acme-billing/1.0', 'Idempotency-Key' => 'order-1042', ]) ->post('https://api.rasket.com/emails', [ 'from' => 'Acme <orders@send.acme.example>', 'to' => ['ronald.williams@example.com'], 'subject' => 'Your order has shipped', 'html' => '<p>Order 1042 shipped today.</p>', ]);
$response->throw();
echo $response->json('id');What sending from Laravel actually involves
To send email from Laravel you would normally add a mailer to config/mail.php and give it SMTP credentials. Calling an email API instead is one Http::post from a service, a job or a listener, and it hands back an id you can store. There is no PHP SDK, so the sample below uses the Http facade, which ships with the framework.
Last updated 2026-09-16. Every field, header and limit below is the one the emails reference carries.
What you get with the key
Five things that arrive with the first request rather than with a later plan.
Idempotent sends
Put an Idempotency-Key on a send and repeat it as often as you like. For 24 hours the same key and payload return the first response instead of a second email, and a different payload under that key is refused rather than sent.
Signed webhooks you can replay
Delivery, bounce, complaint, open and click posted to your endpoint with a timestamp and a signature, retried on failure and replayable from the dashboard.
Inbound mail on your own domain
Receive at your domain on every plan. Each message arrives on a signed webhook with its headers, text and HTML, and its attachments behind signed links.
Templates with typed variables
Publish a template, then send it by ID or alias with the values it declares. Every email records the exact version it was rendered from.
Broadcasts and automations
Contacts with typed properties, topics people subscribe to, and per-contact workflows that wait, branch and send — through the same pipeline as the rest of your mail.
How to send email from Laravel
Six steps, in this order. Everything before the fifth is done once, and only the fifth is about the language you write in.
- 1
Create an API key
Open API keys in the dashboard and create one. It is shown once and stored hashed, so copy it then. Put it in your environment as RASKET_API_KEY and read it from there; a key committed to a repository is a key you have to rotate.
- 2
Add a sending domain
POST /domains with a domain you control. A subdomain such as send.acme.example is the usual choice, because it keeps this mail's reputation separate from the address your people write from. The response carries a records array.
- 3
Publish the DNS records
Every row of records goes into your DNS: the DKIM TXT record at rasket._domainkey, and the two records that give the domain its own return path. Nothing sends from the domain until they resolve.
- 4
Verify the domain
POST /domains/{domain_id}/verify. The domain comes back with a status on each record, and once it reads verified you can send from any address on it. An unverified sender is refused rather than quietly dropped.
- 5
Send your first email from Laravel
Post the message with the sample above. Carry an Idempotency-Key — yours or your queue's retry cannot then turn into a second email — and a User-Agent, which every request has to have. A 200 with an id means we have taken responsibility for the message.
- 6
Subscribe a webhook and check its signature
POST /webhooks with an https endpoint and the events you care about. Delivery, bounce, complaint, open and click arrive there with svix-id, svix-timestamp and svix-signature; verify against the raw body before anything parses it.
Verify webhooks in Laravel
$request->getContent() is the raw body. Read it before $request->all() or $request->json(), exclude the route from CSRF verification, and pass the string with the headers to the svix/svix package's Webhook::verify(). A body Laravel has already decoded and re-encoded is a different string from the one that was signed.
The five steps a verifier performs, in seven languages, are on the webhooks reference.
Read the long version
Sending email from Laravel: the full guide covers attachments, scheduling, suppressions and what to do when a message bounces.
Questions about Laravel
Do I need an SMTP server to send email from Laravel?
No. A mailer in config/mail.php exists to speak SMTP for you; an HTTPS API replaces it with one request and one key. Rasket has no SMTP relay, so if you need Mail::to(...)->send(...) to keep working through a driver, this is not a drop-in.
Is there a PHP SDK?
Not today. The Http facade covers it: withToken for the bearer, withHeaders for the User-Agent and the idempotency key, and post with an array that becomes the JSON body. ->throw() turns a non-2xx into an exception your handler already knows about.
Where do I keep the API key in a Laravel app?
Put RASKET_API_KEY in .env, surface it in config/services.php, and read it with config('services.rasket.key'). Calling env() outside a config file breaks the moment somebody runs config:cache, because env() then returns null and the send fails with no key.
How do I stop a retry from sending the same email twice?
Send an Idempotency-Key header built from the model the mail is about. A queued job that fails and is retried then repeats the same key, and for 24 hours that returns the first response instead of sending again; a different payload under that key is refused.
How do I verify a Rasket webhook in Laravel?
composer require svix/svix, read $request->getContent() first, and pass it with the svix-id, svix-timestamp and svix-signature headers to Webhook::verify(). Exclude the route from CSRF protection, store the event, and answer 400 when verification throws.
Keep reading
Make your first send
Create a key, verify a domain, and post your first message from Laravel. The free plan does not expire.