Guide · PHP
How to send email with Laravel
Point Laravel's mailer at the Stack Emails SMTP relay with a few .env values, then send Mailables as usual.
Last reviewed November 2026
1. Set up
You need a Stack Emails API key (create one free) and a verified sending domain.
Update .env:
MAIL_MAILER=smtp
MAIL_HOST=smtp.stackemails.com
MAIL_PORT=465
MAIL_ENCRYPTION=ssl
MAIL_USERNAME=stackemails
MAIL_PASSWORD=se_live_xxxxxxxxxxxx
MAIL_FROM_ADDRESS=hello@mail.acme.com
MAIL_FROM_NAME="Acme"
(In Laravel 11+, MAIL_SCHEME=smtps replaces MAIL_ENCRYPTION=ssl for port 465.)
2. Send your first email
use App\Mail\WelcomeMail;
use Illuminate\Support\Facades\Mail;
Mail::to($user->email)->send(new WelcomeMail($user));
// Or queue it so the request returns immediately:
Mail::to($user->email)->queue(new WelcomeMail($user));
A successful request returns 202 with the message id, for example { "id": "msg_5b1f0c6c2a8e4e0f", "status": "queued" }. Errors return a JSON body with error.code and error.message (see errors).
Calling the API directly
Laravel's HTTP client works too, which is handy for scheduling or tags:
use Illuminate\Support\Facades\Http;
Http::withToken(env("STACKEMAILS_API_KEY"))
->post("https://stackemails.com/v1/emails", [
"from" => "Acme <hello@mail.acme.com>",
"to" => $user->email,
"subject" => "Your invoice",
"html" => view("emails.invoice", ["user" => $user])->render(),
"scheduled_at" => now()->addHour()->toIso8601String(),
])
->throw();
Production checklist
- Keep the API key in an environment variable or secret manager, never in client-side code.
- Add an
Idempotency-Keyheader to retries so a timeout never sends twice (idempotency). - Subscribe to webhooks for bounces and complaints.
- Check your domain's SPF, DKIM and DMARC records.
- Start from a tested email template for password resets, receipts and invites.