PHPackages                             edward144/php-mailer-failover - 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. edward144/php-mailer-failover

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

edward144/php-mailer-failover
=============================

A PHP Mailer class that allows for multiple redundant SMTP services to be configured.

v1.0.0(2y ago)07MITPHPPHP &gt;=7.2

Since Apr 11Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Edward144/PHPMailer-Failover)[ Packagist](https://packagist.org/packages/edward144/php-mailer-failover)[ RSS](/packages/edward144-php-mailer-failover/feed)WikiDiscussions main Synced 1mo ago

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

PHPMailer Failover
==================

[](#phpmailer-failover)

A PHPMailer class that allows for the configuration of multiple redundant SMTP services. Each service is attempted in turn and if it fails then the next is used. If all services fail then the mail will be logged to a local file for debugging and so that the mail is not lost.

---

### Installation

[](#installation)

This package is now on Packagist, so you can simply run `composer require edward144/php-mailer-failover`.

Create a composer.json file or amend your existing one. Add this Github repository and require the latest version.

```
{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/Edward144/PHPMailer-Failover.git"
    }
  ],
  "require": {
    "edward144/php-mailer-failover": "^1.0"
  },
  "minimum-stability": "stable"
}

```

Run `composer install`

---

### Configuration

[](#configuration)

A number of constants must be defined for the class to operate. An example of these can be found within **tests/config.example.php**. These should be stored in a secure location as your SMTP credentials are required.

- `MAILER_FAILOVER_SMTP` - an array of SMTP services to use, these will be attempted in order.

    ```
    'service_name' => [
      'host'  => 'smtp.service.com',
      'port' => 587,
      'username' => 'username',
      'password' => 'apikey',
      'encryption' => 'tls' //If omitted then PHPMailer::ENCRYPTION_SMTPS will be used
    ],
    ...

    ```
- `MAILER_FAILOVER_DEBUG_LEVEL` - an integer debug level as defined by PHPMailer, default is 2

    - 0 - Debug off
    - 1 - Client to Server messages
    - 2 - As 1 plus Server to Client messages
    - 3 - As 2 plus connection status
    - 4 - All messages
- `MAILER_FAILOVER_DEBUG_LOCATION` - the absolute path to the location where debug logs and failed mails will be stored, include a trailing slash
- `MAILER_FAILOVER_FROM` - the default email address that mail will be sent from
- `MAILER_FAILOVER_FROM_FRIENDLY` - the default friendlt name that mail will be sent from

---

### Usage

[](#usage)

Include the class, require **vendor/autoload.php** and include your defined constants.

You can then add utilize a variety of methods to configure your mail.

```

Use Edward144\PHPMailer-Failover\Mailer

require __DIR__ . '/path/to/vendor/autoload.php';
include __DIR__ . '/path/to/config.php';

$mail = new Mailer();

$mail->addTo('john.smith@example.com'); //Add a single address without a friendly name

$mail->addTo('john.smith@example.com', 'John Smith'); //Add a single address with a friendly name

$mail->addTo([
  'john.smith@example.com',
  'jane.doe@example.com'
]); //Add an array of addresses without friendly names

$mail->addTo([
  'John Smith' => 'john.smith@example.com',
  'Jane Doe' => 'jane.doe@example.com'
]); //Add an array of addresses with friendly names

$mail->addTo([
  'John Smith' => 'john.smith@example.com',
  'jane.doe@example.com'
]); //A mix of emails with and without friendlies can be supplied

$mail->addCc($address, $friendly); //Add a CC address, this can be used the same ways as addTo
$mail->addBcc($address, $friendly); //Add a BCC address, this can also be used the same ways as addTo

$mail->subject('This is my subject);
$mail->body('This is my HTML message!, true); //HTML body, a plaintext version is generated by default, pass a second false parameter to omit this
$mail->altBody('This is my plaintext message!'); //Plaintext body, this should be set before the HTML body, unless the automatic plaintext generation has been disabled.

$mail->from('another.from@example.com', 'Optional Friendly Name'); //Override the default from address and friendly name

$mail->addAttachment('absolute/path/to/attachment.txt'); //Add a single attachment

$mail->addAttachment('absolute/path/to/attachment.txt', 'custom-attachment.txt'); //Add a single attachment with a custom filename

$mail->addAttachment([
  'path/to/attachment-1.txt',
  'path/to/attachment-2.pdf'
]); //An array of attachments without custom filenames

$mail->addAttachment([
  'text-attachment.txt' => 'path/to/attachment-1.txt',
  'pdf-attachment.pdf' => 'path/to/attachment-2.pdf'
]); //An array of attachments with custom filenames

$mail->addAttachment([
  'text-attachment.txt' => 'path/to/attachment-1.txt',
  'path/to/attachment-2.pdf'
]); //A mix of attachments with and without custom filenames can be supplied

$mail->send(); //Send the mail
//true will be returned if a service succeeded
//false if all services failed but the message was logged locally
//An error message will be returned in other cases (an incorrect parameter was supplied, the log file failed to open)

```

---

### Credits

[](#credits)

- [PHPMailer](https://packagist.org/packages/phpmailer/phpmailer)
- [Html2Text](https://packagist.org/packages/html2text/html2text)

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

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

Total

4

Last Release

760d ago

Major Versions

v0.2.1 → v1.0.02024-04-13

### Community

Maintainers

![](https://www.gravatar.com/avatar/83e0c1b3ffe9a985254f8b9f053b34952a809a12ba63dcf630aff062ef3ca920?d=identicon)[edward144](/maintainers/edward144)

---

Top Contributors

[![Edward144](https://avatars.githubusercontent.com/u/12558771?v=4)](https://github.com/Edward144 "Edward144 (26 commits)")

### Embed Badge

![Health badge](/badges/edward144-php-mailer-failover/health.svg)

```
[![Health](https://phpackages.com/badges/edward144-php-mailer-failover/health.svg)](https://phpackages.com/packages/edward144-php-mailer-failover)
```

###  Alternatives

[putyourlightson/craft-campaign

Send and manage email campaigns, contacts and mailing lists.

6435.0k1](/packages/putyourlightson-craft-campaign)[ivantcholakov/codeigniter-phpmailer

A CodeIgniter 3 compatible email-library powered by PHPMailer.

25313.9k](/packages/ivantcholakov-codeigniter-phpmailer)[msp/smtp

SMTP with PHPMailer

2129.4k](/packages/msp-smtp)[fof/webhooks

Automatically notify Discord, Slack, and Microsoft Teams when events happen on your Flarum forum.

2518.3k](/packages/fof-webhooks)[nfephp-org/sped-mail

API para geração e envio dos emails relacionados com o SPED.

1123.7k](/packages/nfephp-org-sped-mail)

PHPackages © 2026

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