PHPackages                             bayfrontmedia/mail-manager - 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. bayfrontmedia/mail-manager

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

bayfrontmedia/mail-manager
==========================

Framework agnostic library to queue and send emails from multiple services using a consistent API.

v2.0.2(1y ago)09291MITPHPPHP ^8.0

Since Sep 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bayfrontmedia/mail-manager)[ Packagist](https://packagist.org/packages/bayfrontmedia/mail-manager)[ Docs](https://github.com/bayfrontmedia/mail-manager)[ RSS](/packages/bayfrontmedia-mail-manager/feed)WikiDiscussions master Synced today

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Mail Manager
------------

[](#mail-manager)

Framework agnostic library to queue and send emails from multiple services using a consistent API.

**NOTE:** Development is currently underway to integrate additional mail services (adapters) to Mail Manager, and these will be released as they are developed.

- [License](#license)
- [Author](#author)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)

License
-------

[](#license)

This project is open source and available under the [MIT License](LICENSE).

Author
------

[](#author)

[![Bayfront Media](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)](https://camo.githubusercontent.com/0c0163913b2092e97dbf9684970adaf86f2f25871298d3d28b2dff4bf75b2915/68747470733a2f2f63646e312e6f6e62617966726f6e742e636f6d2f62666d2f6272616e642f62666d2d6c6f676f2e737667)

- [Bayfront Media homepage](https://www.bayfrontmedia.com?utm_source=github&utm_medium=direct)
- [Bayfront Media GitHub](https://github.com/bayfrontmedia)

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

[](#requirements)

- PHP `^8.0` (Tested up to `8.4`)
- `PDO` PHP extension

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

[](#installation)

```
composer require bayfrontmedia/mail-manager

```

Usage
-----

[](#usage)

**NOTE:** All exceptions thrown by Mail Manager extend `Bayfront\MailManager\Exceptions\MailException`, so you can choose to catch exceptions as narrowly or broadly as you like.

### Adapter

[](#adapter)

A `Bayfront\MailManager\AdapterInterface` must be passed to both the `Bayfront\MailManager\Mail`, and the `Bayfront\MailManager\MailQueue` constructors. There are a variety of adapters available, each with their own required configuration.

In addition, you may also create and use your own adapters to be used with Mail Manager.

All adapters have a `getInstance()` method, which can be used to get the underlying instance used by the adapter.

**PHPMailer**

The PHPMailer adapter allows you to use [PHPMailer](https://github.com/PHPMailer/PHPMailer) for sending messages.

```
use Bayfront\MailManager\Adapters\PHPMailer;

$config = [
    'smtp' => true,
    'smtp_auth' => true,
    'smtp_secure' => 'tls', // STARTTLS or SMTPS
    'host' => 'mail.example.com',
    'port' => 587,
    'username' => 'your_name@example.com',
    'password' => 'your_password',
    'debug' => false
];

try {

    $adapter = new PHPMailer($config);

} catch (AdapterException $e) {
    die($e->getMessage());
}

```

The PHPMailer adapter also has a `testConnection()` method you can use to test for a successful connection to the SMTP server.

### Start using Mail Manager

[](#start-using-mail-manager)

You may choose one of the following classes to use:

The `Bayfront\MailManager\Mail` class allows for the creation and immediate sending of messages. No database is needed.

The `Bayfront\MailManager\MailQueue` class is the same as above, only it requires a `PDO` instance to work with queued messages. Queued messages allow for messages to be sent programmatically at a later date.

**Mail default configuration**

```
use Bayfront\MailManager\Mail;

$mail = new Mail($adapter);

```

**MailQueue default configuration**

```
use Bayfront\MailManager\MailQueue;
use Bayfront\MailManager\Exceptions\QueueException;

$pdo = new PDO('mysql:host=example.com;dbname=database_name', 'username', 'password');

$queue_config = [
    'table' => 'mail_queue', // Name of database table to use
    'max_attempts' => 3 // Maximum number of failed sending attempts before deleting message
];

try {

    $queue = new MailQueue($adapter, $pdo, $queue_config);

} catch (QueueException $e) {
    die($e->getMessage());
}

```

### Public methods

[](#public-methods)

- [create](#create)
- [addAddress](#addaddress)
- [addCc](#addcc)
- [addBcc](#addbcc)
- [addAttachment](#addattachment)
- [discard](#discard)
- [send](#send)

**MailQueue only**

- [addQueue](#addqueue)
- [removeQueue](#removequeue)
- [getQueue](#getqueue)
- [sendQueue](#sendqueue)

---

### create

[](#create)

**Description:**

Create a new message.

**Parameters:**

- `$message` (array)

**Returns:**

- (self)

**Throws**

- `Bayfront\MailManager\Exceptions\MessageException`

**Example:**

```
$message = [
    'to' => [ // Array of recipients
        [
            'address' => 'to@example.com'.
            'name' => 'Recipient name' // Optional
        ]
    ],
    'from' => [
        'address' => 'you@example.com'
        'name' => 'Your name' // Optional
    ],
    'subject' => 'Message subject',
    'body' => 'Message body'
];

try {

    $mail->create($message);

} catch (MessageException $e) {
    die($e->getMessage());
}

```

---

### addAddress

[](#addaddress)

**Description:**

Add a "To" recipient.

**Parameters:**

- `$address` (string)
- `$name = NULL` (string|null): If `NULL`, a name will not be defined

**Returns:**

- (self)

**Example:**

```
$mail->addAddress('jane.doe@example.com', 'Jane Doe');

```

---

### addCc

[](#addcc)

**Description:**

Add a "Cc" recipient.

**Parameters:**

- `$address` (string)
- `$name = NULL` (string|null): If `NULL`, a name will not be defined

**Returns:**

- (self)

**Example:**

```
$mail->addCC('jane.doe@example.com', 'Jane Doe');

```

---

### addBcc

[](#addbcc)

**Description:**

Add a "Bcc" recipient.

**Parameters:**

- `$address` (string)
- `$name = NULL` (string|null): If `NULL`, a name will not be defined

**Returns:**

- (self)

**Example:**

```
$mail->addBCC('jane.doe@example.com', 'Jane Doe');

```

---

### addAttachment

[](#addattachment)

**Description:**

Add an attachment.

**Parameters:**

- `$file` (string): Path to the file
- `$name = NULL` (string|null): New name to assign to file. If `NULL`, the existing name will be used.

**Returns:**

- (self)

**Example:**

```
$mail->addAttachment('/path/to/existing/image.jpg', 'new-name.jpg');

```

---

### discard

[](#discard)

**Description:**

Discard message.

**Parameters:**

- None

**Returns:**

- (self)

**Example:**

```
$mail->discard();

```

---

### send

[](#send)

**Description:**

Send message.

**Parameters:**

- None

**Returns:**

- (void)

**Throws:**

- `Bayfront\MailManager\MessageException`

**Example:**

```
$mail->send();

```

---

### addQueue

[](#addqueue)

**NOTE:** This method is only available with the `MailQueue` class.

**Description:**

Queue message.

**Parameters:**

- `$date_due` (`\DateTimeInterface`)
- `$priority = 5` (int): Messages will be sent in order by due date sorted by priority in descending order

**Returns:**

- (void)

**Throws:**

- `Bayfront\MailManager\QueueException`

**Example:**

```
$message = [
    'to' => [ // Array of recipients
        [
            'address' => 'to@example.com'.
            'name' => 'Recipient name' // Optional
        ]
    ],
    'from' => [
        'address' => 'you@example.com'
        'name' => 'Your name' // Optional
    ],
    'subject' => 'Message subject',
    'body' => 'Message body'
];

try {

    $mail->create($message);

} catch (MessageException $e) {
    die($e->getMessage());
}

try {

    $mail->addQueue(new \Datetime('2020-10-01 10:35:00'));

} catch (QueueException $e) {
    die($e->getMessage());
}

```

---

### removeQueue

[](#removequeue)

**NOTE:** This method is only available with the `MailQueue` class.

**Description:**

Remove a given ID from the queue.

**Parameters:**

- `$id` (int): Unique `id` from the database table

**Returns:**

- (bool)

**Throws:**

- `Bayfront\MailManager\QueueException`

**Example:**

```
$mail->removeQueue(35);

```

---

### getQueue

[](#getqueue)

**NOTE:** This method is only available with the `MailQueue` class.

**Description:**

Get all messages in queue that are due, up to a given limit.

**Parameters:**

- `$limit = 0` (int): `0` to get all

**Returns:**

- (array)

**Throws:**

- `Bayfront\MailManager\QueueException`

**Example:**

```
try {

    print_r($mail->getQueue());

} catch (QueueException $e) {
    die($e->getMessage());
}

```

---

### sendQueue

[](#sendqueue)

**NOTE:** This method is only available with the `MailQueue` class.

**Description:**

Send messages in queue that are due, up to a given limit.

**Parameters:**

- `$limit = 0` (int): `0` to send all

**Returns:**

- (array)

**Throws:**

- `Bayfront\MailManager\QueueException`

**Example:**

```
try {

    $results = $mail->sendQueue(50); // Send up to 50 queued messages

} catch (QueueException $e) {
    die($e->getMessage());
}

```

The returned array contains a result summary with the following structure:

```
[
    'sent' => 0, // Number of messages sent
    'removed' => 0, // Number of messages removed (exceeded max attempts)
    'failed' => 0, // Number of messages failed
    'failed_ids' => [] // Unique ID's of failed messages
];

```

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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 ~519 days

Total

4

Last Release

557d ago

Major Versions

1.0.0 → v2.0.02023-01-26

PHP version history (2 changes)1.0.0PHP &gt;=7.1.0

v2.0.0PHP ^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/5ad62c8d0e69358fd63b16fdaa71d5359231cd0cf660bbc3419071dc705c63a8?d=identicon)[bayfrontmedia](/maintainers/bayfrontmedia)

---

Top Contributors

[![robinsonjohn](https://avatars.githubusercontent.com/u/24327848?v=4)](https://github.com/robinsonjohn "robinsonjohn (10 commits)")

---

Tags

emailmailpdophpphpmailemailpdo

### Embed Badge

![Health badge](/badges/bayfrontmedia-mail-manager/health.svg)

```
[![Health](https://phpackages.com/badges/bayfrontmedia-mail-manager/health.svg)](https://phpackages.com/packages/bayfrontmedia-mail-manager)
```

###  Alternatives

[opcodesio/mail-parser

Parse emails without the mailparse extension

228.8M11](/packages/opcodesio-mail-parser)[railsware/mailtrap-php

The Mailtrap SDK provides methods for all API functions.

60929.1k](/packages/railsware-mailtrap-php)[henrique-borba/php-sieve-manager

A modern (started in 2022) PHP library for the ManageSieve protocol (RFC5804) to create/edit Sieve scripts (RFC5228). Used by Cypht Webmail.

28142.6k4](/packages/henrique-borba-php-sieve-manager)[benhall14/php-imap-reader

A PHP class that makes working with IMAP in PHP simple.

3519.6k](/packages/benhall14-php-imap-reader)[juanparati/brevosuite

Complete Brevo integration with Laravel

1014.8k](/packages/juanparati-brevosuite)

PHPackages © 2026

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