PHPackages                             webgrade-cloud/sendmetrics-laravel - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. webgrade-cloud/sendmetrics-laravel

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

webgrade-cloud/sendmetrics-laravel
==================================

A strict Laravel SDK for the SendMetrics transactional email API.

03

Since May 26Compare

[ Source](https://github.com/webgrade-cloud/sendmetrics-laravel)[ Packagist](https://packagist.org/packages/webgrade-cloud/sendmetrics-laravel)[ RSS](/packages/webgrade-cloud-sendmetrics-laravel/feed)WikiDiscussions Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

 [ ![SendMetrics](art/sendmetrics-logo.svg) ](https://sendmetrics.eu)

 [![Tests](https://github.com/webgrade-cloud/sendmetrics-laravel/actions/workflows/tests.yml/badge.svg)](https://github.com/webgrade-cloud/sendmetrics-laravel/actions/workflows/tests.yml) [![Latest Version on Packagist](https://camo.githubusercontent.com/8ad02d424362883143fd4add8c948c4b26e46abda39382c9da48f4d943bf17a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f77656267726164652d636c6f75642f73656e646d6574726963732d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/webgrade-cloud/sendmetrics-laravel) [![Total Downloads](https://camo.githubusercontent.com/779b34444fa0aeba1b59abebe535bf4136f0bd2586d33da0f371f57d3cb784eb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77656267726164652d636c6f75642f73656e646d6574726963732d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/webgrade-cloud/sendmetrics-laravel) [![License](https://camo.githubusercontent.com/88cb07b66ff2eb93d822633dde60663a48982af889562b989d61dea2bb545a25/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656267726164652d636c6f75642f73656e646d6574726963732d6c61726176656c2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/webgrade-cloud/sendmetrics-laravel)

SendMetrics Laravel SDK
=======================

[](#sendmetrics-laravel-sdk)

SendMetrics is transactional email infrastructure for teams that need clean delivery primitives, strict API contracts, and operational visibility without owning SMTP complexity in every application.

This package is the official Laravel SDK for the SendMetrics Email API. It provides a first-class Laravel mail driver, a typed API client for advanced use cases, auto-discovery, publishable configuration, strict payload validation, and predictable exception handling.

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 11, 12, or 13

Installation
------------

[](#installation)

```
composer require webgrade-cloud/sendmetrics-laravel
```

Laravel auto-discovers the service provider and facade.

Publish the configuration file:

```
php artisan vendor:publish --tag=sendmetrics-config
```

Add your credentials:

```
MAIL_MAILER=sendmetrics
SENDMETRICS_API_KEY=
SENDMETRICS_API_URL=https://sendmetrics.eu/api
```

Configuration
-------------

[](#configuration)

The package publishes `config/sendmetrics.php`:

```
return [
    'api_key' => env('SENDMETRICS_API_KEY'),
    'api_url' => env('SENDMETRICS_API_URL', 'https://sendmetrics.eu/api'),
    'timeout' => (int) env('SENDMETRICS_TIMEOUT', 10),
    'connect_timeout' => (int) env('SENDMETRICS_CONNECT_TIMEOUT', 5),
];
```

The package registers the `sendmetrics` mailer automatically. If you prefer to keep every mailer explicitly listed in `config/mail.php`, add:

```
'default' => env('MAIL_MAILER', 'sendmetrics'),

'mailers' => [
    'sendmetrics' => [
        'transport' => 'sendmetrics',
    ],
],
```

The SDK is intentionally strict. Payload keys must match the SendMetrics API contract exactly.

Laravel Mail
------------

[](#laravel-mail)

Set SendMetrics as your default mailer:

```
MAIL_MAILER=sendmetrics
SENDMETRICS_API_KEY=sm_xxx
SENDMETRICS_API_URL=https://sendmetrics.eu/api
```

Then use Laravel Mail normally:

```
use Illuminate\Support\Facades\Mail;

Mail::to('customer@example.com')->send(new WelcomeCustomer);
```

Mailables, Markdown mailables, `Mail::send`, `Mail::raw`, global `mail.from`, reply-to, CC, BCC, custom headers, tags, metadata, attachments, and queued mailables are sent through the SendMetrics API.

### Tags and Metadata

[](#tags-and-metadata)

Use Laravel's native mailable envelope API:

```
use Illuminate\Mail\Mailables\Envelope;

public function envelope(): Envelope
{
    return new Envelope(
        subject: 'Invoice paid',
        tags: ['billing'],
        metadata: [
            'account_id' => $this->accountId,
        ],
    );
}
```

### Attachments

[](#attachments)

Laravel attachment APIs work as usual:

```
use Illuminate\Mail\Mailables\Attachment;

public function attachments(): array
{
    return [
        Attachment::fromPath(storage_path('invoices/invoice.pdf'))
            ->as('invoice.pdf')
            ->withMime('application/pdf'),
    ];
}
```

Raw data attachments are supported too:

```
Attachment::fromData(fn () => $this->pdf, 'invoice.pdf')
    ->withMime('application/pdf');
```

Notifications
-------------

[](#notifications)

Laravel's built-in mail notification channel uses the configured mailer, so no SendMetrics-specific notification code is required:

```
use Illuminate\Support\Facades\Notification;

Notification::send($users, new InvoicePaidNotification);
```

Inside the notification:

```
use Illuminate\Notifications\Messages\MailMessage;

public function toMail(object $notifiable): MailMessage
{
    return (new MailMessage)
        ->subject('Invoice paid')
        ->line('Your invoice has been paid.');
}
```

Queues
------

[](#queues)

Queued mailables and queued notifications continue to use Laravel's queue system:

```
Mail::to('customer@example.com')->queue(new WelcomeCustomer);
```

```
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;

final class InvoicePaidNotification extends Notification implements ShouldQueue
{
    // ...
}
```

Retries, backoff, failed jobs, and queue workers stay in Laravel, while delivery goes through SendMetrics.

Advanced API Client
-------------------

[](#advanced-api-client)

Most applications should use Laravel Mail. The direct client remains available for product-specific flows where you want to bypass Laravel's mail abstractions.

Use dependency injection when you want explicit, testable code:

```
use WebgradeCloud\SendMetrics\Data\EmailMessage;
use WebgradeCloud\SendMetrics\SendMetricsClient;

final class SendWelcomeEmail
{
    public function __construct(
        private readonly SendMetricsClient $sendMetrics,
    ) {}

    public function handle(string $email): void
    {
        $response = $this->sendMetrics->sendEmail(new EmailMessage(
            fromEmail: 'welcome@example.com',
            fromName: 'Example App',
            toEmail: $email,
            subject: 'Welcome to Example App',
            htmlBody: 'Your account is ready.',
            textBody: 'Your account is ready.',
        ));

        $response->messageId;
    }
}
```

You may also send an exact API payload:

```
use WebgradeCloud\SendMetrics\Facades\SendMetrics;

$response = SendMetrics::sendEmail([
    'from' => [
        'email' => 'billing@example.com',
        'name' => 'Billing',
    ],
    'to' => [
        [
            'email' => 'customer@example.com',
            'name' => null,
        ],
    ],
    'subject' => 'Invoice paid',
    'html_body' => 'Your invoice was paid.',
    'text_body' => 'Your invoice was paid.',
    'headers' => [
        'X-Billing-Event' => 'invoice-paid',
    ],
    'tags' => ['billing'],
    'metadata' => [
        'invoice_id' => 'inv_123',
    ],
    'attachments' => [],
]);
```

Accepted keys:

- `from`
- `to` — exactly one primary recipient
- `cc`
- `bcc`
- `reply_to`
- `subject`
- `html_body`
- `text_body`
- `headers`
- `tags`
- `metadata`
- `attachments`

Error Handling
--------------

[](#error-handling)

When using Laravel Mail, SendMetrics API errors are surfaced as Symfony mail transport exceptions:

```
use Symfony\Component\Mailer\Exception\TransportExceptionInterface;

try {
    Mail::to('customer@example.com')->send(new WelcomeCustomer);
} catch (TransportExceptionInterface $exception) {
    report($exception);
}
```

The transport maps authentication errors, validation failures, rate limits, and server errors to clear mail transport exception messages. Debug details from the SendMetrics API response are attached to the Symfony exception when available.

When using the advanced API client, catch the SDK exceptions directly:

```
use WebgradeCloud\SendMetrics\Exceptions\ApiException;
use WebgradeCloud\SendMetrics\Exceptions\ConfigurationException;
use WebgradeCloud\SendMetrics\Exceptions\InvalidPayloadException;
use WebgradeCloud\SendMetrics\Exceptions\TransportException;

try {
    $sendMetrics->sendEmail($message);
} catch (InvalidPayloadException $exception) {
    report($exception);
} catch (ConfigurationException $exception) {
    report($exception);
} catch (ApiException $exception) {
    $exception->statusCode;
    $exception->responseBody;
} catch (TransportException $exception) {
    report($exception);
}
```

`ApiException` exposes the HTTP status code and decoded response body, including rate-limit and quota responses returned by the SendMetrics API.

Roadmap
-------

[](#roadmap)

- Template sending
- Batch sending
- Webhook helpers
- Inbound parsing
- Campaign APIs

The package intentionally does not include inbound parsing, a templates engine, batch campaigns, or a webhook server yet.

Security
--------

[](#security)

Report security issues through GitHub Security Advisories or by contacting `security@webgrade.cloud`.

Credits
-------

[](#credits)

SendMetrics is built by Webgrade Cloud.

License
-------

[](#license)

The MIT License (MIT). See [LICENSE](LICENSE) for more information.

###  Health Score

10

—

LowBetter than 0% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity11

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b9461bee3e80bc675ed502fc5f608e700ec34812dc1a57a02ba4fa5000c70534?d=identicon)[webgrade](/maintainers/webgrade)

### Embed Badge

![Health badge](/badges/webgrade-cloud-sendmetrics-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/webgrade-cloud-sendmetrics-laravel/health.svg)](https://phpackages.com/packages/webgrade-cloud-sendmetrics-laravel)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
