Send Emails with PHP / Laravel
Learn how to send transactional emails using PostStack and PHP / Laravel.
1. Install the SDK
bash
# No external packages needed — uses built-in cURL2. Initialize the client
php
$apiKey = 'sk_live_...';
$baseUrl = 'https://api.poststack.dev';3. Send an email
php
<?php
$apiKey = getenv('POSTSTACK_API_KEY');
$payload = json_encode([
'from' => 'hello@yourdomain.com',
'to' => 'user@example.com',
'subject' => 'Hello from PHP!',
'html' => '<h1>Welcome!</h1>',
]);
$ch = curl_init('https://api.poststack.dev/v1/emails');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
],
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response;Notes
- Uses built-in PHP cURL — no Composer packages required
- For Laravel, you can also configure PostStack as an SMTP transport in config/mail.php
Ready to send emails with PHP / Laravel?
Create a free account and get your API key in under a minute.