PHPackages                             baibaratsky/php-mailgun - 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. baibaratsky/php-mailgun

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

baibaratsky/php-mailgun
=======================

Mailgun API PHP library and Yii extension (as well as Yii2)

v1.2.0(10y ago)3224.6k↑133.3%12BSD-3-ClausePHPPHP &gt;=5.2

Since Oct 11Pushed 9y ago4 watchersCompare

[ Source](https://github.com/baibaratsky/php-mailgun)[ Packagist](https://packagist.org/packages/baibaratsky/php-mailgun)[ Docs](http://github.com/baibaratsky/php-mailgun)[ RSS](/packages/baibaratsky-php-mailgun/feed)WikiDiscussions master Synced 1mo ago

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

Mailgun API PHP library
=======================

[](#mailgun-api-php-library)

[![Packagist](https://camo.githubusercontent.com/804c49d492c4f66a6d7d3f73fbf27d6014ebba0d0631d818ff15e9809f2e4b0b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6261696261726174736b792f7068702d6d61696c67756e2e737667)](https://github.com/baibaratsky/php-mailgun/blob/master/LICENSE.md)[![Packagist](https://camo.githubusercontent.com/cd4c71130f61ff9225d4ffd8a3474094d64a3eba483eeab2898049fd0c5c73d0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6261696261726174736b792f7068702d6d61696c67756e2e737667)](https://packagist.org/packages/baibaratsky/php-mailgun)[![Packagist](https://camo.githubusercontent.com/3211e395b449392fc3e8c7609e362270448d3f33b546d9296b69cf8312d67cff/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6261696261726174736b792f7068702d6d61696c67756e2e737667)](https://packagist.org/packages/baibaratsky/php-mailgun)

The library requires PHP 5.2 compiled with [cURL extension](http://www.php.net/manual/en/book.curl.php).

\##How to install

1. Install [Composer](http://getcomposer.org/):

    ```
    curl -sS https://getcomposer.org/installer | php

    ```
2. Add php-mailgun dependency:

    ```
    php composer.phar require baibaratsky/php-mailgun:1.2.*

    ```

\##How to use

It’s pretty easy to send a message using this library:

```
require_once(__DIR__ . '/vendor/autoload.php'); // Require autoload file generated by composer

$mailgun = new MailgunApi('example.com', 'key-somekey');

$message = $mailgun->newMessage();
$message->setFrom('me@example.com', 'Andrei Baibaratsky');
$message->addTo('you@yourdomain.com', 'My dear user');
$message->setSubject('Mailgun API library test');
$message->setText('Amazing! It’s working!');
$message->addTag('test'); // All the Mailgun-specific attributes, such as tags, vars, tracking, etc. are supported

$message->enableTestMode(); // Don’t forget to remove this string if you really want the message to be sent

// You can also use dry run to test your code without making real API requests (only for sendMessage())
// $mailgun->enableDryRun();

echo $message->send();
```

Batch sending is also supported. You can use [recipient variables](http://documentation.mailgun.com/user_manual.html#batch-sending) to customize messages.

The library fully supports listing, creating, updating, and deleting of mailing lists and their members:

```
MailgunList[]        getMailingLists(int $limit = 100, int $skip = 0)
MailgunList          getMailingList(string $listAddress)
MailgunList          createMailingList(MailgunList $mailingList)
MailgunList          updateMailingList(string $listAddress, MailgunList $mailingList)
bool                 deleteMailingList(string $listAddress)
MailgunListMember[]  getMailingListMembers(string $listAddress, int $limit = 100, int $skip = 0)
MailgunListMember    getMailingListMember(string $listAddress, string $memberAddress)
MailgunListMember    addMemberToMailingList(string $listAddress, MailgunListMember $member, bool $upsert = false)
MailgunList          addMultipleMembersToMailingList(string $listAddress, array $members)
MailgunListMember    updateMailingListMember(string $listAddress, string $memberAddress, MailgunListMember $member)
bool                 deleteMailingListMember(string $listAddress, string $memberAddress)
array                getMailingListStats(string $listAddress)

```

Unsubscribes-related methods:

```
MailgunUnsubscribe[] getUnsubscribes(int $limit = 100, int $skip = 0)
MailgunUnsubscribe[] getUserUnsubscribes(string $userAddress)
bool                 createUnsubscribe(MailgunUnsubscribe $unsubscribe)
bool                 deleteUnsubscribe(string $id)
bool                 deleteUserUnsubscribes(string $userAddress)

```

Spam Complaints:

```
MailgunComplaint[]   getComplaints(int $limit = 100, int $skip = 0)
MailgunComplaint     getComplaint(string $userAddress)
bool                 createComplaint(MailgunComplaint $complaint)
bool                 deleteComplaint(string $userAddress)

```

Bounces:

```
MailgunBounce[]      getBounces(int $limit = 100, int $skip = 0)
MailgunBounce        getBounce(string $userAddress)
bool                 createBounce(MailgunBounce $bounce)
bool                 deleteBounce(string $userAddress)

```

Routes:

```
MailgunRoute[]       getRoutes(int $limit = 100, int $skip = 0)
MailgunRoute         getRoute(string $id)
MailgunRoute         createRoute(MailgunRoute $route)
MailgunRoute         updateRoute(string $id, MailgunRoute $route)
bool                 deleteRoute(string $id)

```

Webhook signature validation:

```
if (!$mailgun->validateHook($_POST)) {
    echo 'Bad signature!';
}
```

\###Yii extension Yii users can use this library as an extension. Just put *php-mailgun* in your extensions directory or use Composer, and add some code in the *components* section of your config file:

```
...
    'components' => array(
        ...
        'mailgun' => array(
            'class' => 'vendor.baibaratsky.php-mailgun.MailgunYii',
            'domain' => 'example.com',
            'key' => 'key-somekey',
            'tags' => array('yii'), // You may also specify some Mailgun parameters
            'enableTracking' => false,
        ),
        ...
    ),
...
```

That’s all! Your application is ready to send messages. For example:

```
$message = Yii::app()->mailgun->newMessage();
$message->setFrom('me@example.com', 'Andrei Baibaratsky');
$message->addTo('you@yourdomain.com', 'My dear user');
$message->setSubject('Mailgun API library test');

// You can use views to build your messages instead of setText() or setHtml():
$message->renderText('myView', array('myParam' => 'Awesome!'));

echo $message->send();
```

All the methods of the main library class are available in the Yii component.

---

Mailgun is a programmable email platform. It allows your application to become a fully-featured email server. Send and receive messages, create mailboxes and email campaigns with ease. You can find more information about Mailgun and its API here:

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 84.3% 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 ~83 days

Total

5

Last Release

3906d ago

### Community

Maintainers

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

---

Top Contributors

[![baibaratsky](https://avatars.githubusercontent.com/u/1774061?v=4)](https://github.com/baibaratsky "baibaratsky (43 commits)")[![chuprik](https://avatars.githubusercontent.com/u/802946?v=4)](https://github.com/chuprik "chuprik (6 commits)")[![martinbrambati2](https://avatars.githubusercontent.com/u/195799390?v=4)](https://github.com/martinbrambati2 "martinbrambati2 (2 commits)")

---

Tags

emailmailmailgunyii-extensionyii2-extensionmailemailyii2mailgunyiimailing lists

### Embed Badge

![Health badge](/badges/baibaratsky-php-mailgun/health.svg)

```
[![Health](https://phpackages.com/badges/baibaratsky-php-mailgun/health.svg)](https://phpackages.com/packages/baibaratsky-php-mailgun)
```

###  Alternatives

[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)[tuyakhov/yii2-notifications

The extension provides support for sending notifications across a variety of delivery channels, including mail, SMS, Slack etc. Notifications may also be stored in a database so they may be displayed in your web interface.

6735.5k2](/packages/tuyakhov-yii2-notifications)[rmrevin/yii2-postman

Mail module for Yii2.

2612.3k](/packages/rmrevin-yii2-postman)

PHPackages © 2026

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