Integration
Send emails from Laravel with Postkit
Send transactional emails from Laravel using Postkit's REST API with the HTTP client. No Mailable or mail driver needed — just a direct API call.
1. Set your API key
# .env POSTKIT_API_KEY=pk_live_...
2. Send an email
php
// app/Http/Controllers/EmailController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
class EmailController extends Controller
{
public function sendWelcome(Request $request)
{
$response = Http::withToken(config('services.postkit.key'))
->post('https://api.postkit.eu/v1/emails', [
'from' => 'hello@yourapp.eu',
'to' => $request->email,
'subject' => 'Welcome aboard!',
'html' => "<h1>Welcome, {$request->name}!</h1>",
]);
return $response->json();
}
}3. Handle webhooks
Postkit sends delivery events (sent, delivered, bounced, opened, clicked) via HMAC-SHA256 signed webhooks following the Standard Webhooks specification.
php
// app/Http/Controllers/WebhookController.php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class WebhookController extends Controller
{
public function postkit(Request $request)
{
$body = $request->getContent();
$msgId = $request->header('webhook-id', '');
$timestamp = $request->header('webhook-timestamp', '');
$signature = $request->header('webhook-signature', '');
$secretB64 = str_replace('whsec_', '', config('services.postkit.webhook_secret'));
$secret = base64_decode($secretB64);
$content = "{$msgId}.{$timestamp}.{$body}";
$expected = base64_encode(hash_hmac('sha256', $content, $secret, true));
$valid = collect(explode(' ', $signature))
->contains(fn ($sig) =>
hash_equals(str_replace('v1,', '', $sig), $expected)
);
if (! $valid) {
return response()->json(['error' => 'Invalid signature'], 401);
}
$event = json_decode($body, true);
logger("Postkit event: {$event['type']}");
return response()->json(['received' => true]);
}
}