Skip to content

Laravel

Laravel’s SMTP mailer works with SpacePost without any packages.

.env
MAIL_MAILER=smtp
MAIL_SCHEME=smtp
MAIL_HOST=smtp.spacepost.dev
MAIL_PORT=25976
MAIL_USERNAME=spacepost
MAIL_PASSWORD=sp_live_YOUR_API_KEY
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="hello@acme.com"
MAIL_FROM_NAME="Acme"

Laravel 11 and later read MAIL_SCHEME=smtp and upgrade the connection with STARTTLS; Laravel 10 and earlier read MAIL_ENCRYPTION=tls. Keeping both lines works on every version. Do not use smtps or ssl: implicit TLS (port 465) is not offered yet.

Send as usual:

use Illuminate\Support\Facades\Mail;
use App\Mail\OrderShipped;
Mail::to($user)->send(new OrderShipped($order));

Add SpacePost’s control headers in your Mailable:

use Illuminate\Mail\Mailables\Headers;
public function headers(): Headers
{
return new Headers(text: [
'X-SpacePost-Tags' => 'category=order, order_id=' . $this->order->id,
]);
}

Mailables sent with Mail::queue() work as normal; the queue worker talks to SpacePost over SMTP. Keep the number of concurrent workers within the rate limit.