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

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

cosnavel/mailgun-php
====================

The Mailgun SDK provides methods for all API functions.

3.5.2(4y ago)13.2kMITPHPPHP ^7.3 || ^8.0

Since Aug 16Pushed 4y agoCompare

[ Source](https://github.com/Cosnavel/mailgun-php)[ Packagist](https://packagist.org/packages/cosnavel/mailgun-php)[ RSS](/packages/cosnavel-mailgun-php/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (9)Versions (44)Used By (0)

Mailgun PHP client
==================

[](#mailgun-php-client)

This is the Mailgun PHP SDK. This SDK contains methods for easily interacting with the Mailgun API. Below are examples to get you started. For additional examples, please see our official documentation at

[![Latest Version](https://camo.githubusercontent.com/4bbb98c8f62222263edbe1adf047e4d3d3d9c109377cf9530954b885b29647fe/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6d61696c67756e2f6d61696c67756e2d7068702e7376673f7374796c653d666c61742d737175617265)](https://github.com/mailgun/mailgun-php/releases)[![Total Downloads](https://camo.githubusercontent.com/d299ae7f40bb42bbdc3ae4d455aa3194b307035d27127a56bb543dc5e2e63a85/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d61696c67756e2f6d61696c67756e2d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mailgun/mailgun-php)[![Join the chat at https://gitter.im/mailgun/mailgun-php](https://camo.githubusercontent.com/ee316ab2784d4f36516e572fefa0af5db4795fddc97644865c2c7b82656174e2/68747470733a2f2f6261646765732e6769747465722e696d2f6d61696c67756e2f6d61696c67756e2d7068702e737667)](https://gitter.im/mailgun/mailgun-php?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

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

[](#installation)

To install the SDK, you will need to be using [Composer](http://getcomposer.org/)in your project. If you aren't using Composer yet, it's really simple! Here's how to install composer:

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

The Mailgun API Client is not hard coupled to Guzzle, Buzz or any other library that sends HTTP messages. Instead, it uses the [PSR-18](https://www.php-fig.org/psr/psr-18/) client abstraction. This will give you the flexibility to choose what [PSR-7 implementation](https://packagist.org/providers/psr/http-message-implementation)and [HTTP client](https://packagist.org/providers/psr/http-client-implementation)you want to use.

If you just want to get started quickly you should run the following command:

```
composer require cosnavel/mailgun-php symfony/http-client nyholm/psr7
```

Usage
-----

[](#usage)

You should always use Composer autoloader in your application to automatically load your dependencies. All the examples below assume you've already included this in your file:

```
require 'vendor/autoload.php';
use Mailgun\Mailgun;
```

Here's how to send a message using the SDK:

```
// First, instantiate the SDK with your API credentials
$mg = Mailgun::create('key-example'); // For US servers
$mg = Mailgun::create('key-example', 'https://api.eu.mailgun.net'); // For EU servers

// Now, compose and send your message.
// $mg->messages()->send($domain, $params);
$mg->messages()->send('example.com', [
  'from'    => 'bob@example.com',
  'to'      => 'sally@example.com',
  'subject' => 'The PHP SDK is awesome!',
  'text'    => 'It is so simple to send a message.'
]);
```

Attention: `$domain` must match to the domain you have configured on [app.mailgun.com](https://app.mailgun.com/app/domains).

### All usage examples

[](#all-usage-examples)

You will find more detailed documentation at [/doc](doc/index.md) and on [https://documentation.mailgun.com](https://documentation.mailgun.com/en/latest/api_reference.html).

### Response

[](#response)

The result of an API call is, by default, a domain object. This will make it easy to understand the response without reading the documentation. One can just read the doc blocks on the response classes. This provides an excellent IDE integration.

```
$mg = Mailgun::create('key-example');
$dns = $mg->domains()->show('example.com')->getInboundDNSRecords();

foreach ($dns as $record) {
  echo $record->getType();
}
```

If you'd rather work with an array than an object you can inject the `ArrayHydrator`to the Mailgun class.

```
use Mailgun\Hydrator\ArrayHydrator;

$configurator = new HttpClientConfigurator();
$configurator->setApiKey('key-example');

$mg = new Mailgun($configurator, new ArrayHydrator());
$data = $mg->domains()->show('example.com');

foreach ($data['receiving_dns_records'] as $record) {
  echo isset($record['record_type']) ? $record['record_type'] : null;
}
```

You can also use the `NoopHydrator` to get a PSR7 Response returned from the API calls.

**Warning: When using `NoopHydrator` there will be no exceptions on a non-200 response.**

### Debugging

[](#debugging)

Debugging the PHP SDK can be helpful when things aren't working quite right. To debug the SDK, here are some suggestions:

Set the endpoint to Mailgun's Postbin. A Postbin is a web service that allows you to post data, which then you can display it through a browser. Using Postbin is an easy way to quickly determine what data you're transmitting to Mailgun's API.

**Step 1 - Create a new Postbin.**Go to . The Postbin will generate a special URL. Save that URL.

**Step 2 - Instantiate the Mailgun client using Postbin.**

*Tip: The bin id will be the URL part after bin.mailgun.net. It will be random generated letters and numbers. For example, the bin id in this URL () is `aecf68de`.*

```
use Mailgun\HttpClient\HttpClientConfigurator;
use Mailgun\Hydrator\NoopHydrator;

$configurator = new HttpClientConfigurator();
$configurator->setEndpoint('http://bin.mailgun.net/aecf68de');
$configurator->setApiKey('key-example');
$configurator->setDebug(true);

$mg = new Mailgun($configurator, new NoopHydrator());

# Now, compose and send your message.
$mg->messages()->send('example.com', [
  'from'    => 'bob@example.com',
  'to'      => 'sally@example.com',
  'subject' => 'The PHP SDK is awesome!',
  'text'    => 'It is so simple to send a message.'
]);
```

### Additional Info

[](#additional-info)

For usage examples on each API endpoint, head over to our official documentation pages.

This SDK includes a [Message Builder](src/Message/README.md), [Batch Message](src/Message/README.md).

Message Builder allows you to quickly create the array of parameters, required to send a message, by calling a methods for each parameter. Batch Message is an extension of Message Builder, and allows you to easily send a batch message job within a few seconds. The complexity of batch messaging is eliminated!

Framework integration
---------------------

[](#framework-integration)

If you are using a framework you might consider these composer packages to make the framework integration easier.

- [tehplague/swiftmailer-mailgun-bundle](https://github.com/tehplague/swiftmailer-mailgun-bundle) for Symfony
- [katanyoo/yii2-mailgun-mailer](https://github.com/katanyoo/yii2-mailgun-mailer) for Yii2
- [narendravaghela/cakephp-mailgun](https://github.com/narendravaghela/cakephp-mailgun) for CakePHP
- [drupal/mailgun](https://www.drupal.org/project/mailgun) for Drupal

Contribute
----------

[](#contribute)

This SDK is an Open Source under the MIT license. It is, thus, maintained by collaborators and contributors.

Feel free to contribute in any way. As an example you may:

- Trying out the `dev-master` code
- Create issues if you find problems
- Reply to other people's issues
- Review PRs

### Running the test code

[](#running-the-test-code)

If you want to run the tests you should run the following commands:

```
git clone git@github.com:mailgun/mailgun-php.git
cd mailgun-php
composer update
composer test

```

Support and Feedback
--------------------

[](#support-and-feedback)

Be sure to visit the Mailgun official [documentation website](http://documentation.mailgun.com/) for additional information about our API.

If you find a bug, please submit the issue in Github directly. [Mailgun-PHP Issues](https://github.com/mailgun/mailgun-php/issues)

As always, if you need additional assistance, drop us a note through your account at .

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity81

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~58 days

Total

41

Last Release

1700d ago

Major Versions

0.7 → 1.02013-08-20

v1.8 → v2.02016-04-02

2.8.1 → 3.0.0-beta12019-04-09

2.x-dev → 3.1.02020-10-08

PHP version history (4 changes)v2.0PHP ^5.5|^7.0

2.7.0PHP ^5.5 || ^7.0

3.0.0-beta1PHP ^7.1

3.3.0PHP ^7.3 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/42392570?v=4)[Niclas Kahlmeier](/maintainers/Cosnavel)[@Cosnavel](https://github.com/Cosnavel)

---

Top Contributors

[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (209 commits)")[![travelton](https://avatars.githubusercontent.com/u/241714?v=4)](https://github.com/travelton "travelton (76 commits)")[![DavidGarciaCat](https://avatars.githubusercontent.com/u/7809429?v=4)](https://github.com/DavidGarciaCat "DavidGarciaCat (66 commits)")[![pirogoeth](https://avatars.githubusercontent.com/u/472488?v=4)](https://github.com/pirogoeth "pirogoeth (12 commits)")[![obukhov-sergey](https://avatars.githubusercontent.com/u/617482?v=4)](https://github.com/obukhov-sergey "obukhov-sergey (9 commits)")[![z38](https://avatars.githubusercontent.com/u/3948085?v=4)](https://github.com/z38 "z38 (8 commits)")[![cerealean](https://avatars.githubusercontent.com/u/6100756?v=4)](https://github.com/cerealean "cerealean (8 commits)")[![Pavlico](https://avatars.githubusercontent.com/u/45973917?v=4)](https://github.com/Pavlico "Pavlico (7 commits)")[![aradoje](https://avatars.githubusercontent.com/u/30075502?v=4)](https://github.com/aradoje "aradoje (6 commits)")[![iwahara](https://avatars.githubusercontent.com/u/3982522?v=4)](https://github.com/iwahara "iwahara (6 commits)")[![yoye](https://avatars.githubusercontent.com/u/570307?v=4)](https://github.com/yoye "yoye (6 commits)")[![svenbw](https://avatars.githubusercontent.com/u/837206?v=4)](https://github.com/svenbw "svenbw (5 commits)")[![qpautrat](https://avatars.githubusercontent.com/u/1844413?v=4)](https://github.com/qpautrat "qpautrat (5 commits)")[![nathanntg](https://avatars.githubusercontent.com/u/194728?v=4)](https://github.com/nathanntg "nathanntg (5 commits)")[![Littlesqx](https://avatars.githubusercontent.com/u/16516151?v=4)](https://github.com/Littlesqx "Littlesqx (4 commits)")[![indapublic](https://avatars.githubusercontent.com/u/856260?v=4)](https://github.com/indapublic "indapublic (4 commits)")[![finwe](https://avatars.githubusercontent.com/u/195675?v=4)](https://github.com/finwe "finwe (4 commits)")[![ZebulanStanphill](https://avatars.githubusercontent.com/u/19592990?v=4)](https://github.com/ZebulanStanphill "ZebulanStanphill (4 commits)")[![shakaran](https://avatars.githubusercontent.com/u/14254?v=4)](https://github.com/shakaran "shakaran (4 commits)")[![jchamberlain](https://avatars.githubusercontent.com/u/3923548?v=4)](https://github.com/jchamberlain "jchamberlain (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mailgun/mailgun-php

The Mailgun SDK provides methods for all API functions.

1.1k28.9M168](/packages/mailgun-mailgun-php)[openai-php/client

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

5.8k22.6M232](/packages/openai-php-client)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[theodo-group/llphant

LLPhant is a library to help you build Generative AI applications.

1.5k311.5k5](/packages/theodo-group-llphant)[deeplcom/deepl-php

Official DeepL API Client Library

2616.2M66](/packages/deeplcom-deepl-php)[jolicode/slack-php-api

An up to date PHP client for Slack's API

2534.4M12](/packages/jolicode-slack-php-api)

PHPackages © 2026

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