How to Send Email with Laravel

This guide shows a practical Laravel integration for sending transactional email through POST /api/v1/message.

1. Add your API key to config

Store the key in .env and expose it through config/services.php.


// config/services.php
'sendwich' => [
    'key' => env('SENDWICH_API_KEY'),
],

2. Send an email with the HTTP client


use Illuminate\Support\Facades\Http;

$response = Http::withToken(config('services.sendwich.key'))
    ->asJson()
    ->post('https://sendwich.dev/api/v1/message', [
        'from' => 'Acme ',
        'to' => ['customer@example.com'],
        'subject' => 'Welcome to Acme',
        'html' => '

Your account is ready.

', 'text' => 'Your account is ready.', ]); if (! $response->successful()) { report(new \RuntimeException('Sendwich send failed: '.$response->body())); }

3. Production checklist

  • Use verified domains for your from address.
  • Queue sending jobs for better request performance.
  • Track failures and retry transient errors.

Need examples in other languages? See guides for Node.js, PHP, and Ruby.