PHPackages                             khaleejinfotech/multi-tenant-mailer - 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. khaleejinfotech/multi-tenant-mailer

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

khaleejinfotech/multi-tenant-mailer
===================================

The `MultiTenantMailer` is a powerful and flexible email-sending class designed for multi-tenant applications. It simplifies the process ofconfiguring and sending emails while supporting multiple tenants with different settings.

v1.0.14(1y ago)032MITPHP

Since Oct 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ibilalkhilji/multi-tenant-mailer)[ Packagist](https://packagist.org/packages/khaleejinfotech/multi-tenant-mailer)[ Docs](https://khaleejinfotech.com)[ RSS](/packages/khaleejinfotech-multi-tenant-mailer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (15)Used By (0)

Multi Tenant Mailer
===================

[](#multi-tenant-mailer)

[![Multi Tenant Mailer](banner.png)](banner.png)[![GitHub Issues or Pull Requests](https://camo.githubusercontent.com/213116cb55be81ae1fc197717ce6ac8bd8ec4d8e1b54b25f11adc17b555b76e7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6962696c616c6b68696c6a692f6d756c74692d74656e616e742d6d61696c6572)](https://camo.githubusercontent.com/213116cb55be81ae1fc197717ce6ac8bd8ec4d8e1b54b25f11adc17b555b76e7/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6962696c616c6b68696c6a692f6d756c74692d74656e616e742d6d61696c6572)[![GitHub Tag](https://camo.githubusercontent.com/1e71102a4dad03cf3e36bf7e2f263c6f4b1d58feb0287bb1c6566323e3fba331/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f6962696c616c6b68696c6a692f6d756c74692d74656e616e742d6d61696c65723f6c6162656c3d76657273696f6e)](https://camo.githubusercontent.com/1e71102a4dad03cf3e36bf7e2f263c6f4b1d58feb0287bb1c6566323e3fba331/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f7461672f6962696c616c6b68696c6a692f6d756c74692d74656e616e742d6d61696c65723f6c6162656c3d76657273696f6e)[![GitHub contributors](https://camo.githubusercontent.com/9da9445dc3148b690b1bbff5da7ed75f6093468afc56df845471c35d940dcc10/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f6962696c616c6b68696c6a692f6d756c74692d74656e616e742d6d61696c6572)](https://camo.githubusercontent.com/9da9445dc3148b690b1bbff5da7ed75f6093468afc56df845471c35d940dcc10/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f636f6e7472696275746f72732f6962696c616c6b68696c6a692f6d756c74692d74656e616e742d6d61696c6572)[![GitHub Repo stars](https://camo.githubusercontent.com/5cb08fec1dd98d2ba506d6ee7f0821da45228ed088812656f9c0f49698d29ac5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6962696c616c6b68696c6a692f6d756c74692d74656e616e742d6d61696c6572)](https://camo.githubusercontent.com/5cb08fec1dd98d2ba506d6ee7f0821da45228ed088812656f9c0f49698d29ac5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6962696c616c6b68696c6a692f6d756c74692d74656e616e742d6d61696c6572)

The `MultiTenantMailer` is a powerful and flexible email-sending library designed for multi-tenant applications. It simplifies the process of configuring and sending emails while supporting multiple tenants with different settings.

Features
--------

[](#features)

- Support for multiple tenants with unique SMTP configurations.
- Easy-to-use API for setting up email properties (host, port, username, etc.).
- Ability to queue emails for background processing.
- Support for HTML and plain text emails.

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

[](#installation)

1. **Install via Composer**: If you haven't done so, install the package using Composer:

    ```
    composer require khaleejinfotech/multi-tenant-mailer
    ```
2. **Register the service provider**: Open your `config/app.php` file and add the service provider to the `providers` array.

    ```
    'providers' => [
        // ...
        Khaleejinfotech\MultiTenantMailer\MultiTenantMailerServiceProvider::class,
    ],
    ```
3. **Publish Configuration:** After installation, publish the configuration file and any required resources:

    ```
    php artisan vendor:publish --provider="Khaleejinfotech\MultiTenantMailer\MultiTenantMailerServiceProvider"
    ```

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

[](#configuration)

You can configure the queue\_class in the published configuration file (config/multi-tenant-mailer.php) like this:

```
return [
    'queue_class' => \Khaleejinfotech\MultiTenantMailer\Jobs\MultiTenantMailerQueued::class,
];
```

Usage
-----

[](#usage)

### MultiTenantMailer

[](#multitenantmailer)

#### Initialize the Mailer

[](#initialize-the-mailer)

```
use Khaleejinfotech\MultiTenantMailer\MultiTenantMailer;

$mailer = new MultiTenantMailer();
$mailer->init($host, $port, $username, $password, $encryption);
```

#### Set Email Properties

[](#set-email-properties)

```
$mailer->setFrom($fromAddresses, $fromName)
  ->setTo($toAddresses, $toName)
  ->setSubject($subject)
  ->setBody($body)
  ->setContentType('text/html')
  ->setAttachments($attachments)
  ->shouldQueue(); // Optional: Set to true if you want to queue the email
```

#### Send the Email

[](#send-the-email)

```
$mailer->send();
```

### MultiTenantMailerSettings

[](#multitenantmailersettings)

#### Create and Configure Settings

[](#create-and-configure-settings)

```
use Khaleejinfotech\MultiTenantMailer\Contracts\MultiTenantMailerSettings;

$mailerSettings = new MultiTenantMailerSettings();
$mailerSettings->setHost($host)
   ->setPort($port)
   ->setUsername($username)
   ->setPassword($password)
   ->setEncryption($encryption)
   ->setFromAddress($fromAddress, $fromName);
```

by this you can directly pass the settings object to the mailer instance.
Here is the example

```
use Khaleejinfotech\MultiTenantMailer\MultiTenantMailer;

$mailer = new MultiTenantMailer();
$mailer->withSettings($mailerSettings);
```

Using Facades
-------------

[](#using-facades)

If you prefer to use facades for cleaner syntax, you can utilize the facades you've created.

### Using MultiTenantMailer Facade

[](#using-multitenantmailer-facade)

```
use Khaleejinfotech\MultiTenantMailer\Facades\MultiTenantMailer;

MultiTenantMailer::init($host, $port, $username, $password, $encryption)
  ->setFrom($fromAddresses, $fromName)
  ->setTo($toAddresses, $toName)
  ->setSubject($subject)
  ->setBody($body)
  ->setContentType('text/html')
  ->setAttachments($attachments)
  ->shouldQueue()
  ->send();
```

### Using MultiTenantMailerSettings Facade

[](#using-multitenantmailersettings-facade)

```
use Khaleejinfotech\MultiTenantMailer\Facades\MultiTenantMailerSettings;

MultiTenantMailerSettings::setHost($host)
  ->setPort($port)
  ->setUsername($username)
  ->setPassword($password)
  ->setEncryption($encryption)
  ->setFromAddress($fromAddress, $fromName);
```

Notification Driver Support
---------------------------

[](#notification-driver-support)

```
public function via(object $notifiable): array
{
    return ['tenant_mailer'];
}

public function toTenantMailer($notifiable): MultiTenantMailer
{
    return (new MultiTenantMailer)
        ->setHost(config('mail.mailers.smtp.host'))
        ->setPort(config('mail.mailers.smtp.port'))
        ->setUsername(config('mail.mailers.smtp.username'))
        ->setPassword(config('mail.mailers.smtp.password'))
        ->setEncryption(config('mail.mailers.smtp.encryption'))
        ->setFrom(config('mail.from.address'))
        ->setTo($notifiable)
        ->setSubject('Subject')
        ->setBody($this->toMail($notifiable)->render());
}
```

the `setBody()` can have either Notification/Mailable or the self mailable method to render the message;

#### 1. Notification/Mailable Object

[](#1-notificationmailable-object)

```
->setBody(new MailTestMessge());
```

#### 2. Self `$this->toMail($notifiable)->render()` method

[](#2-self-this-tomailnotifiable-render-method)

```
->setBody($this->toMail($notifiable)->render());
```

Queues
------

[](#queues)

The `MultiTenantMailer` class provides the ability to define specific queues for processing emails, giving you control over how and when emails are queued.

### Setting the Queue

[](#setting-the-queue)

You can set a queue name or identifier using the `setOnQueue` method. This allows you to specify a queue that suits your system’s job-handling requirements.

```
->onQueue('emails');
```

Events
------

[](#events)

The library includes the following events:

`MailFailed:` Triggered when sending an email fails.

`MailSuccess:` Triggered when an email is sent successfully.

Available Methods
-----------------

[](#available-methods)

### Class MultiTenantMailer

[](#class-multitenantmailer)

MethodSummary`init(string $host, int $port, string $username, string $password, string $encryption)`Initializes mailer settings.`withSettings(MultiTenantMailerSettings $mailerSettings)`Sets mailer settings from a `MultiTenantMailerSettings` instance.`setHost(string $host)`Sets the mail server host.`getHost(): string`Retrieves the mail server host.`setPort(int $port)`Sets the mail server port.`getPort(): int`Retrieves the mail server port.`setUsername(string $username)`Sets the username for the mail server.`getUsername(): string`Retrieves the username for the mail server.`setPassword(string $password)`Sets the password for the mail server.`getPassword(): string`Retrieves the password for the mail server.`setEncryption(string $encryption)`Sets the encryption type (e.g., 'tls', 'ssl').`getEncryption(): string`Retrieves the encryption type.`setTo(array|string $addresses, string $name = null)`Sets the recipient's email address(es) and optional name.`getToAddresses(): array|string`Retrieves the recipient's email address(es).`getToName(): ?string`Retrieves the name of the recipient.`setCc(array $addresses)`Sets the cc recipient's email address(es) .`getCcAddresses(): array`Retrieves the cc recipient's email address(es).`setBcc(array $addresses)`Sets the bcc recipient's email address(es) .`getBccAddresses(): array`Retrieves the bcc recipient's email address(es).`setFrom(array|string $addresses, string $name = null)`Sets the sender's email address(es) and optional name.`getFromAddresses(): array|string`Retrieves the sender's email address(es).`getFromName(): ?string`Retrieves the name of the sender.`setSubject(string $subject)`Sets the email subject.`setContentType(string $contentType = 'text/html')`Sets the content type (e.g., 'text/html').`shouldQueue()`Marks the email to be queued for sending.`isShouldQueue(): bool`Checks if the email should be queued.`onQueue(BackedEnum|string|null $onQueue = 'default')`Sets the job queue name.`getQueue(): BackedEnum|string|null $onQueue`Retrieves the job queue name.`getStreamOptions(): null|array`Get the stream options.`setStreamOptions(): null|array`Set the stream options.`setBody(Notification|string $notification)`Sets the email body, either from a notification or a plain string.`getBody(): string`Retrieves the email body.`setBodyPart(string $bodyPart)`Sets the plain text body part of the email.`getBodyPart(): string`Retrieves the plain text body part of the email.`setAttachments(array $attachments)`Sets attachments for the email.`getAttachments(): array`Retrieves the attachments for the email.`setHeaders(array $headers)`Sets headers for the email.`getHeaders(): array`Retrieves the headers for the email.`useFallbackConfig()`Sets default email settings if there is no email config set.`stopTransport(bool $b)`Define whether to keep transport running or stopped..`shouldStopTransport(): bool`To stop the transport.`setExtras(array|string $key, mixed $value)`Defines extra data to be used by the mailer.`getExtras(): array`Returns the array of extra data.`send(): int`Sends the email and returns the number of emails sent.### Class MultiTenantMailerSettings

[](#class-multitenantmailersettings)

MethodSummary`setHost(string $host)`Sets the mail server host for the settings.`getHost(): string`Retrieves the mail server host from the settings.`setPort(int $port)`Sets the mail server port for the settings.`getPort(): int`Retrieves the mail server port from the settings.`setUsername(string $username)`Sets the username for the mail server in the settings.`getUsername(): string`Retrieves the username for the mail server from the settings.`setPassword(string $password)`Sets the password for the mail server in the settings.`getPassword(): string`Retrieves the password for the mail server from the settings.`setEncryption(string $encryption)`Sets the encryption type (e.g., 'tls', 'ssl') in the settings.`getEncryption(): string`Retrieves the encryption type from the settings.`setFromName(string $name = null)`Sets the sender's name in the settings.`getFromName(): ?string`Retrieves the sender's name from the settings.`setFromAddress(string $addresses, string $name = null)`Sets the sender's email address and optional name in the settings.`getFromAddress(): ?string`Retrieves the sender's email address from the settings.Exception Handling
------------------

[](#exception-handling)

The MultiTenantMailer class throws MultiTenantMailerException when the required properties (host, port, username, etc.) are not set. Be sure to handle these exceptions to avoid runtime errors.

Contributing
------------

[](#contributing)

Contributions are welcome! Please submit a pull request or open an issue for any improvements or bugs you encounter.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance42

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~7 days

Recently: every ~17 days

Total

14

Last Release

476d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3294fb4f0b9cf3412c757ef470160f819a62a55a13a6e33409f5f5ee19227f94?d=identicon)[kbinfo4u](/maintainers/kbinfo4u)

---

Top Contributors

[![ibilalkhilji](https://avatars.githubusercontent.com/u/14019618?v=4)](https://github.com/ibilalkhilji "ibilalkhilji (16 commits)")

---

Tags

mailemailmailermulti-tenantkhaleej infotech

### Embed Badge

![Health badge](/badges/khaleejinfotech-multi-tenant-mailer/health.svg)

```
[![Health](https://phpackages.com/badges/khaleejinfotech-multi-tenant-mailer/health.svg)](https://phpackages.com/packages/khaleejinfotech-multi-tenant-mailer)
```

###  Alternatives

[voku/bounce-mail-handler

Bounce Mail Handler

49230.9k2](/packages/voku-bounce-mail-handler)[boundstate/yii2-mailgun

Mailgun integration for the Yii framework

28160.6k](/packages/boundstate-yii2-mailgun)[yarcode/yii2-mailgun-mailer

Mailgun mailer implementation for Yii2

1576.0k](/packages/yarcode-yii2-mailgun-mailer)[sandstorm/templatemailer

Neos and Flow package for simple handling of template-based emails, including CSS inlining

1147.3k2](/packages/sandstorm-templatemailer)

PHPackages © 2026

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