sendsend.email

Send email with Laravel

A server-side call to the SendSend API from your Laravel app.

  1. Create a test API key in the dashboard first: it never delivers real email. Switch to a live key once your domain is verified.
  2. Add SENDSEND_API_KEY to .env and expose it in config/services.php as sendsend.key.
  3. Add this to app/Http/Controllers/MailController.php:
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;

class MailController extends Controller
{
    public function send(Request $request)
    {
        $response = Http::withToken(config('services.sendsend.key'))
            ->withHeaders(['Idempotency-Key' => (string) Str::uuid()])
            ->post('https://api.sendsend.email/v1/emails', [
                'from' => 'Acme <hello@mail.acme.com>',
                'to' => [$request->input('to')],
                'subject' => 'Hello from Laravel',
                'html' => '<p>It works!</p>',
            ]);

        return response()->json($response->json(), $response->status());
    }
}

Prefer sending from a queued job so a slow response never holds up a web request.

Good to know