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

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

neurohotep/mailgun-php
======================

The Mailgun SDK provides methods for all API functions.

2.8.3(6y ago)0475MITPHPPHP ^5.5 || ^7.0

Since Aug 16Pushed 6y agoCompare

[ Source](https://github.com/neurohotep/mailgun-php)[ Packagist](https://packagist.org/packages/neurohotep/mailgun-php)[ RSS](/packages/neurohotep-mailgun-php/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (10)Versions (35)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)[![Build Status](https://camo.githubusercontent.com/b5fc1d984e59b32c0a0dfa92055c1fbd1456f2050b49918c73dd68a00469c33a/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d61696c67756e2f6d61696c67756e2d7068702f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/mailgun/mailgun-php)[![Code Coverage](https://camo.githubusercontent.com/a2dc850a1a20232f40f87890816852f97df07bd1a63622a6e946ff2394f22926/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f6d61696c67756e2f6d61696c67756e2d7068702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/mailgun/mailgun-php)[![Quality Score](https://camo.githubusercontent.com/34a5d2b441d6574de3f91e561c1f36c291e8fb5f801e807654b5294fb3f143d1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d61696c67756e2f6d61696c67756e2d7068702e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/mailgun/mailgun-php)[![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 or any other library that sends HTTP messages. It uses the [PSR-18](https://www.php-fig.org/psr/psr-18/) client abstraction. This will give you the flexibilty to choose what PSR-7 implementation and HTTP client to use.

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

```
composer require mailgun/mailgun-php kriswallsmith/buzz nyholm/psr7
```

Usage
-----

[](#usage)

You should always use Composer's 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 find more detailed documentation at [/doc](doc/index.md) and on [https://documentation.mailgun.com](https://documentation.mailgun.com/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 = Mailgun::configure($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 really 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 is then displayed through a browser. This allows you to quickly determine what is actually being transmitted 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".*

```
$configurator = new HttpClientConfigurator();
$configurator->setEndpoint('http://bin.mailgun.net/aecf68de');
$configurator->setDebug(true);
$mg = Mailgun::configure($configurator);

# 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/Mailgun/Messages/README.md), [Batch Message](src/Mailgun/Messages/README.md) and [Opt-In Handler](src/Mailgun/Lists/README.md) component.

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
- [Bogardo/Mailgun](https://github.com/Bogardo/Mailgun) for Laravel
- [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)

We are currently building a new object oriented API client. Feel free to contribute in any way. As an example you may:

- Trying out dev-master the 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

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity70

Established project with proven stability

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

Recently: every ~51 days

Total

33

Last Release

2501d ago

Major Versions

0.7 → 1.02013-08-20

v1.8 → v2.02016-04-02

2.8.1 → 3.0.0-beta12019-04-09

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

2.7.0PHP ^5.5 || ^7.0

3.0.0-beta1PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/1aa4f2d55f5ce6343cdbc6311c0a7b6a499be8924272ba67b645f062a86c8e0b?d=identicon)[umertasov](/maintainers/umertasov)

---

Top Contributors

[![Nyholm](https://avatars.githubusercontent.com/u/1275206?v=4)](https://github.com/Nyholm "Nyholm (195 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 (53 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)")[![cerealean](https://avatars.githubusercontent.com/u/6100756?v=4)](https://github.com/cerealean "cerealean (8 commits)")[![z38](https://avatars.githubusercontent.com/u/3948085?v=4)](https://github.com/z38 "z38 (8 commits)")[![yoye](https://avatars.githubusercontent.com/u/570307?v=4)](https://github.com/yoye "yoye (6 commits)")[![aradoje](https://avatars.githubusercontent.com/u/30075502?v=4)](https://github.com/aradoje "aradoje (6 commits)")[![qpautrat](https://avatars.githubusercontent.com/u/1844413?v=4)](https://github.com/qpautrat "qpautrat (5 commits)")[![finwe](https://avatars.githubusercontent.com/u/195675?v=4)](https://github.com/finwe "finwe (4 commits)")[![shakaran](https://avatars.githubusercontent.com/u/14254?v=4)](https://github.com/shakaran "shakaran (4 commits)")[![nathanntg](https://avatars.githubusercontent.com/u/194728?v=4)](https://github.com/nathanntg "nathanntg (3 commits)")[![maximzasorin](https://avatars.githubusercontent.com/u/13367689?v=4)](https://github.com/maximzasorin "maximzasorin (3 commits)")[![TemirkhanN](https://avatars.githubusercontent.com/u/12416657?v=4)](https://github.com/TemirkhanN "TemirkhanN (3 commits)")[![jchamberlain](https://avatars.githubusercontent.com/u/3923548?v=4)](https://github.com/jchamberlain "jchamberlain (3 commits)")[![zacbrownpayleven](https://avatars.githubusercontent.com/u/15887133?v=4)](https://github.com/zacbrownpayleven "zacbrownpayleven (2 commits)")[![neurohotep](https://avatars.githubusercontent.com/u/12581971?v=4)](https://github.com/neurohotep "neurohotep (2 commits)")[![nmenglund](https://avatars.githubusercontent.com/u/4630452?v=4)](https://github.com/nmenglund "nmenglund (2 commits)")[![semijoelon](https://avatars.githubusercontent.com/u/34149088?v=4)](https://github.com/semijoelon "semijoelon (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mailgun/mailgun-php

The Mailgun SDK provides methods for all API functions.

1.1k30.8M178](/packages/mailgun-mailgun-php)[phpro/http-tools

HTTP tools for developing more consistent HTTP implementations.

28150.5k](/packages/phpro-http-tools)[sylius/sylius

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

8.5k5.9M724](/packages/sylius-sylius)[openai-php/client

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

5.8k28.0M303](/packages/openai-php-client)[m4tthumphrey/php-gitlab-api

GitLab API v4 client for PHP

9515.8M74](/packages/m4tthumphrey-php-gitlab-api)[php-http/httplug-bundle

Symfony integration for HTTPlug

39021.7M60](/packages/php-http-httplug-bundle)

PHPackages © 2026

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