Skip to content

Send email from Laravel

The PHP SDK registers a vaartix mail driver automatically (Laravel 12 and 13), so the Mail facade, Mailables, notifications and queued mail all go through Vaartix. The source is on GitHub at vaartix-mail/vaartix-php and the package is on Packagist.

  1. Install the SDK

    Terminal window
    composer require vaartix/vaartix-php

    The service provider is discovered automatically.

  2. Configure the mailer

    .env
    MAIL_MAILER=vaartix
    MAIL_FROM_ADDRESS=[email protected] # on a domain verified in Vaartix
    VAARTIX_API_KEY=vx_live_...
    VAARTIX_WEBHOOK_SECRET=whsec_...
    config/services.php
    'vaartix' => [
    'key' => env('VAARTIX_API_KEY'),
    'webhook_secret' => env('VAARTIX_WEBHOOK_SECRET'),
    ],
    config/mail.php
    'mailers' => [
    // ...
    'vaartix' => [
    'transport' => 'vaartix',
    ],
    ],
  3. Send as usual

    Mail::to($user)->send(new OrderConfirmed($order));

    Laravel’s ->tag('welcome') and ->metadata('order_id', 42) become Vaartix tags, so you can filter by them in the dashboard. SentMessage::getMessageId() returns the Vaartix email ID.

To call the API directly, inject the client. It’s registered as a singleton from services.vaartix.key:

public function store(Request $request, \Vaartix\Vaartix $vaartix)
{
$vaartix->emails->send([
'from' => 'Acme <[email protected]>',
'to' => $request->user()->email,
'subject' => 'Your order is confirmed',
'html' => view('emails.order-confirmed', ['order' => $order])->render(),
], idempotencyKey: "order-confirmed-{$order->id}");
}

Until your domain is verified, send from @test.vaartix.com to [email protected]: see Test mode.

routes/web.php
use Illuminate\Http\Request;
use Vaartix\Exceptions\WebhookVerificationException;
use Vaartix\Webhook;
Route::post('/webhooks/vaartix', function (Request $request) {
try {
$event = Webhook::verify(
$request->getContent(),
$request->headers->all(),
config('services.vaartix.webhook_secret'),
);
} catch (WebhookVerificationException $e) {
abort(400);
}
if ($event['type'] === 'email.bounced') {
// stop emailing $event['data']['recipient']
}
return response()->noContent();
});