Sending Email with PHP
Framework-agnostic cURL example for any PHP app.
Read guideIntegrate Mailsurge into a Laravel app using the HTTP client — from local config through queued production sends.
Store the key in .env and expose it through config/services.php so config caching works in production.
1
// config/services.php
2
'mailsurge' => [
3
'key' => env('MAILSURGE_API_KEY'),
4
],
Use Laravel's built-in HTTP client with a Bearer token. A 201 response means the message was accepted and queued for delivery.
1
use Illuminate\Support\Facades\Http;
2
3
$response = Http::withToken(config('services.mailsurge.key'))
4
->asJson()
5
->post('https://mailsurge.dev/api/v1/message', [
6
'from' => 'Acme <no-reply@yourdomain.com>',
7
'to' => ['customer@example.com'],
8
'subject' => 'Welcome to Acme',
9
'html' => '<p>Your account is ready.</p>',
10
'text' => 'Your account is ready.',
11
]);
12
13
if (! $response->successful()) {
14
report(new \RuntimeException('Mailsurge send failed: '.$response->body()));
15
}
Move sends off the request cycle and plan for failures before you ship.
Related guides to help you ship production-ready transactional email.
Framework-agnostic cURL example for any PHP app.
Read guideVerify DNS and monitoring before going live.
Read guideVerify a domain, create an API key, and call POST /api/v1/message from your stack.