Looking to hire Laravel developers? Try LaraJobs

laravel-email-relay maintained by elitetools

Description
Custom Laravel email transport that forwards mail via an HTTP relay API.
Last update
2026/08/09 02:31 (dev-master)
License
Links
Downloads
0

Comments
comments powered by Disqus

laravel-email-relay

Latest Version on Packagist License

Custom Laravel email transport that forwards mail via an HTTP relay API.


Requirements

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

Installation

1. Install the package:

composer require elitetools/laravel-email-relay

That's it! The package automatically registers the emailrelay mailer and its service configuration via Laravel's package discovery.


Configuration

Just set these variables in your .env file:

MAIL_MAILER=emailrelay
EMAIL_RELAY_URL=https://your-relay-api.example.com
EMAIL_RELAY_TOKEN=your-secret-token

Usage

Use it like any standard Laravel Mailable. Optionally set the X-Email-Type header to categorize the email on the relay side:

Mail::to($user)->send(
    (new WelcomeMail($user))->withSymfonyMessage(function ($message) {
        $message->getHeaders()->addTextHeader('X-Email-Type', 'Welcome');
    })
);

How it works

  1. Intercepts outgoing mail via a custom Symfony AbstractTransport
  2. Builds a JSON payload with type, sendToAddress, senderName, senderAddress, subject, and body
  3. POSTs to {EMAIL_RELAY_URL}/send with a Bearer token
  4. Throws an exception if the relay returns a non-2xx response

License

MIT