serversmtp / serversmtp-laravel
ServerSMTP mail transport and automation events for Laravel
Requires
- php: >=8.2
- illuminate/mail: ^10.0 || ^11.0 || ^12.0
- illuminate/notifications: ^10.0 || ^11.0 || ^12.0
- illuminate/support: ^10.0 || ^11.0 || ^12.0
- serversmtp/serversmtp-php: ^0.3
- symfony/mailer: ^6.2 || ^7.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
ServerSMTP for Laravel 10, 11 and 12 (PHP 8.2+): a mail transport that sends through the ServerSMTP HTTP API, and a notification channel that triggers ServerSMTP automations (email and SMS). Built on serversmtp/serversmtp-php.
composer require serversmtp/serversmtp-laravel
config/services.php:
'serversmtp' => [ 'key' => env('SERVERSMTP_API_KEY'), 'audience_id' => env('SERVERSMTP_AUDIENCE_ID'), // optional, for the notification channel ],
.env:
MAIL_MAILER=serversmtp SERVERSMTP_API_KEY=em_live_... MAIL_FROM_ADDRESS=comenzi@domeniul-tau.ro
The sender must be on a domain verified in ServerSMTP. Every Mailable, Mail::raw() and mail notification now goes through POST /v1/send, with CC, BCC, Reply-To and attachments (up to 10 files, 10 MB). The returned message ID is the ServerSMTP requestId.
Safe retries
Queued jobs can run twice. Give each email a stable key and a retry never sends it again:
public function headers(): Headers { return new Headers(text: ['Idempotency-Key' => "comanda-{$this->order->id}-confirmare"]); }
Without the header the SDK generates a key for each attempt. Other custom headers are not sent.
Automations and SMS
Create an automation in ServerSMTP for an event (for example comanda.expediata) with email and/or SMS steps, then trigger it from a notification:
use ServerSMTP\Laravel\EventMessage; class OrderShipped extends Notification { public function __construct(private Order $order) {} public function via(object $notifiable): array { return ['serversmtp']; } public function toServerSMTP(object $notifiable): EventMessage { return EventMessage::create('comanda.expediata') ->data(['order_reference' => $this->order->number, 'tracking_number' => $this->order->awb]) ->phone($this->order->phone); } } $user->notify(new OrderShipped($order)); Notification::route('serversmtp', 'client@example.com')->notify(new OrderShipped($order));
The recipient is routeNotificationForServerSMTP() or the notifiable's email; the phone is ->phone() or the notifiable's phone (Romanian mobile numbers). With audience_id set, a missing contact is added to that audience. Or call the client directly: app(ServerSMTP\Client::class)->events->trigger('comanda.platita', $email, $data, $phone).
Errors throw Symfony\Component\Mailer\Exception\TransportException (mail) or ServerSMTP\ServerSMTPException (events), with the HTTP status and the invalid fields.
Docs: https://serversmtp.ro/docs#laravel
Tests
tests/laravel-app-check.php is an Artisan command (serversmtp:check) for a Laravel app with this package installed, run against sdks/contract-server.mjs.
License
MIT © Think AI SRL