PHPackages                             andywahyudi/multi-email-services - 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. andywahyudi/multi-email-services

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

andywahyudi/multi-email-services
================================

A PHP library for handling multiple email service providers with failover support

1.1.0(9mo ago)00MITPHPPHP ^7.4|^8.0

Since Mar 7Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/andywahyudi/email-services)[ Packagist](https://packagist.org/packages/andywahyudi/multi-email-services)[ RSS](/packages/andywahyudi-multi-email-services/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (8)Versions (3)Used By (0)

Email Services Library
======================

[](#email-services-library)

A robust PHP library for handling multiple email service providers with failover support. This library currently supports Mailgun, SendGrid, and Postmark with both API and SMTP implementations.

Features
--------

[](#features)

- Multiple email service provider support
- Automatic failover handling
- Support for both API and SMTP sending methods
- Attachment handling
- CC and BCC support
- HTML email support
- Easy configuration

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

[](#requirements)

- PHP 8.1 or higher
- Composer

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

[](#installation)

```
composer require andywahyudi/multi-email-services
```

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

[](#configuration)

Create a .env file in your project root (copy from .env.example ):

```
# Default Provider Configuration
DEFAULT_EMAIL_PROVIDER=mailgun  # Options: mailgun, sendgrid, postmark

# SendGrid Configuration
SENDGRID_API_KEY=your_sendgrid_api_key_here
SENDGRID_USE_SMTP=false
SENDGRID_FROM_ADDRESS=your_verified_sender@domain.com

# Mailgun Configuration
MAILGUN_API_KEY=your_mailgun_api_key_here
MAILGUN_DOMAIN=your_domain_here
MAILGUN_FROM_ADDRESS=your_sender@your_domain.com
MAILGUN_USE_SMTP=false

# Postmark Configuration
POSTMARK_SERVER_TOKEN=your_postmark_server_token_here
POSTMARK_FROM_ADDRESS=your_sender@your_domain.com
POSTMARK_USE_SMTP=false
```

Usage
-----

[](#usage)

### Basic Usage with Default Provider

[](#basic-usage-with-default-provider)

```
use MultiEmailServices\Library\EmailServiceManager;
use MultiEmailServices\Library\Providers\MailgunService;
use MultiEmailServices\Library\Providers\SendGridService;
use MultiEmailServices\Library\Providers\PostmarkService;

// Initialize the Email Service Manager (will use DEFAULT_EMAIL_PROVIDER from .env)
$emailManager = new EmailServiceManager();

// Configure and add providers
$mailgunConfig = [
    'api_key' => getenv('MAILGUN_API_KEY'),
    'domain' => getenv('MAILGUN_DOMAIN'),
    'from_address' => getenv('MAILGUN_FROM_ADDRESS')
];

$sendGridConfig = [
    'api_key' => getenv('SENDGRID_API_KEY'),
    'from_address' => getenv('SENDGRID_FROM_ADDRESS')
];

$postmarkConfig = [
    'api_key' => getenv('POSTMARK_SERVER_TOKEN'),
    'from_address' => getenv('POSTMARK_FROM_ADDRESS')
];

// Add providers to the manager
$emailManager
    ->addProvider(new MailgunService($mailgunConfig))
    ->addProvider(new SendGridService($sendGridConfig))
    ->addProvider(new PostmarkService($postmarkConfig));

// Optionally change default provider at runtime
$emailManager->setDefaultProvider('sendgrid');

// Get current default provider
$currentProvider = $emailManager->getDefaultProvider();

// Get list of available providers
$availableProviders = $emailManager->getAvailableProviders();

// Send email (will use default provider first)
try {
    $emailManager->send(
        'recipient@example.com',
        'Test Subject',
        'Hello World!',
        ['from' => 'sender@yourdomain.com']
    );
} catch (\Exception $e) {
    echo "Failed to send email: " . $e->getMessage();
}
```

### Using SMTP

[](#using-smtp)

To use SMTP instead of API, update your configuration:

```
$mailgunConfig = [
    'use_smtp' => true,
    'smtp_host' => 'smtp.mailgun.org',
    'smtp_port' => 587,
    'smtp_username' => 'your_smtp_username',
    'smtp_password' => 'your_smtp_password',
    'from_address' => 'your_sender@your_domain.com'
];
```

### Provider Failover

[](#provider-failover)

The library will:

1. Attempt to send using the default provider first (if configured).
2. If the default provider fails, it will automatically try other available providers.
3. If all providers fail, it will throw an exception with detailed error messages.

Available Providers
-------------------

[](#available-providers)

1. Mailgun

    - API and SMTP support.
    - Domain verification required.
    - Supports attachments, CC, and BCC.
2. SendGrid

    - API and SMTP support.
    - Sender verification required.
    - Supports attachments, CC, and BCC.
3. Postmark

    - API and SMTP support.
    - Server token required.
    - Supports attachments, CC, and BCC.

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

[](#error-handling)

The library implements a failover system. If one provider fails, it automatically tries the next available provider. If all providers fail, an exception is thrown with detailed error messages from each provider.

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

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

This project is licensed under the MIT License.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance55

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

Total

2

Last Release

297d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/65bfe13025ec32bd72989c893925f5a9bae1d20d5fc77f7f99e5ca41ede82b4e?d=identicon)[andywahyudi](/maintainers/andywahyudi)

---

Top Contributors

[![andywahyudi](https://avatars.githubusercontent.com/u/50721511?v=4)](https://github.com/andywahyudi "andywahyudi (5 commits)")

---

Tags

emailemail-senderemailservicesmailgunpostmarksendgrid

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/andywahyudi-multi-email-services/health.svg)

```
[![Health](https://phpackages.com/badges/andywahyudi-multi-email-services/health.svg)](https://phpackages.com/packages/andywahyudi-multi-email-services)
```

###  Alternatives

[mailersend/laravel-driver

MailerSend Laravel Driver

87732.8k4](/packages/mailersend-laravel-driver)[dotdigital/dotdigital-magento2-extension

Dotdigital for Magento 2

50374.2k18](/packages/dotdigital-dotdigital-magento2-extension)[swiftmade/laravel-sendgrid-notification-channel

Laravel Notification Channel for Sengrid.com

26287.7k](/packages/swiftmade-laravel-sendgrid-notification-channel)[sproutcms/cms

Enterprise content management and framework

241.6k4](/packages/sproutcms-cms)

PHPackages © 2026

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