PHPackages                             renzojohnson/mailgun-api - 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. renzojohnson/mailgun-api

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

renzojohnson/mailgun-api
========================

Lightweight PHP wrapper for Mailgun API. Send emails, validate addresses, manage domains. Zero dependencies beyond ext-curl.

v0.26.03.16(3mo ago)00MITPHPPHP ^8.4

Since Mar 17Pushed 3mo agoCompare

[ Source](https://github.com/renzojohnson/mailgun-api)[ Packagist](https://packagist.org/packages/renzojohnson/mailgun-api)[ Docs](https://renzojohnson.com)[ RSS](/packages/renzojohnson-mailgun-api/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Mailgun API
===========

[](#mailgun-api)

[![Latest Version](https://camo.githubusercontent.com/76957d399e37ddb2aba71470cd415dbe235fd2e6f6d38ae39c58827ac4f164ae/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72656e7a6f6a6f686e736f6e2f6d61696c67756e2d6170692e737667)](https://packagist.org/packages/renzojohnson/mailgun-api)[![PHP Version](https://camo.githubusercontent.com/bf6b44660ab29e6e70bc7df48b60e3bd1a711a2e13ef8d906804be4077361553/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f72656e7a6f6a6f686e736f6e2f6d61696c67756e2d6170692e737667)](https://packagist.org/packages/renzojohnson/mailgun-api)[![License](https://camo.githubusercontent.com/d6310b23a137d33f29aa335b059bf208ab15e52afe97a84e68c5354b7d1f00a4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f72656e7a6f6a6f686e736f6e2f6d61696c67756e2d6170692e737667)](https://github.com/renzojohnson/mailgun-api/blob/main/LICENSE)

Lightweight PHP wrapper for Mailgun API. Send emails, validate addresses, manage domains. Zero dependencies beyond ext-curl.

**Author:** [Renzo Johnson](https://renzojohnson.com)

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

[](#requirements)

- **PHP 8.4 or higher**
- `ext-curl`
- `ext-json`

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

[](#installation)

```
composer require renzojohnson/mailgun-api
```

Quick Start
-----------

[](#quick-start)

```
use RenzoJohnson\Mailgun\Mailgun;

$mailgun = new Mailgun('key-your-api-key', 'mg.yourdomain.com');

// Send a simple text email
$mailgun->sendText(
    'sender@mg.yourdomain.com',
    'recipient@example.com',
    'Hello from Mailgun',
    'This is the email body.'
);
```

Send HTML Email
---------------

[](#send-html-email)

```
$mailgun->sendHtml(
    'sender@mg.yourdomain.com',
    'recipient@example.com',
    'Welcome!',
    'WelcomeThanks for signing up.',
    'Welcome! Thanks for signing up.' // optional plain text fallback
);
```

Advanced Email Builder
----------------------

[](#advanced-email-builder)

```
use RenzoJohnson\Mailgun\Message\Email;

$email = new Email(
    'sender@mg.yourdomain.com',
    'recipient@example.com',
    'Order Confirmation',
    text: 'Your order has been confirmed.',
    html: 'Order Confirmed'
);

$email->cc('manager@example.com')
    ->bcc('archive@example.com')
    ->replyTo('support@example.com')
    ->header('X-Campaign', 'welcome-series')
    ->variable('order_id', '12345')
    ->tag('transactional');

$mailgun->send($email);
```

Domain Info
-----------

[](#domain-info)

```
// Get domain details
$info = $mailgun->getDomainInfo();

// List all domains
$domains = $mailgun->listDomains();
```

Events &amp; Stats
------------------

[](#events--stats)

```
// Get sending events
$events = $mailgun->getEvents(['event' => 'delivered', 'limit' => 10]);

// Get delivery stats (last 7 days)
$stats = $mailgun->getStats('delivered', 7);
```

Email Validation
----------------

[](#email-validation)

```
// Validate an email address (requires validation API key)
$result = $mailgun->validateEmail('user@example.com');
```

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

[](#error-handling)

```
use RenzoJohnson\Mailgun\Exception\ApiException;

try {
    $mailgun->sendText('from@mg.example.com', 'to@example.com', 'Test', 'Body');
} catch (ApiException $e) {
    echo $e->getMessage(); // "Mailgun API error (401): Forbidden"
}
```

Links
-----

[](#links)

- [Packagist](https://packagist.org/packages/renzojohnson/mailgun-api)
- [GitHub](https://github.com/renzojohnson/mailgun-api)
- [Issues](https://github.com/renzojohnson/mailgun-api/issues)
- [Author](https://renzojohnson.com)

License
-------

[](#license)

MIT License. Copyright (c) 2026 [Renzo Johnson](https://renzojohnson.com).

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance81

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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

Unknown

Total

1

Last Release

99d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e1b69733e3d1fd486158d322c23d99281623046b3c357529c9930e50d73fcda?d=identicon)[renzo.johnson](/maintainers/renzo.johnson)

---

Top Contributors

[![renzojohnson](https://avatars.githubusercontent.com/u/4695400?v=4)](https://github.com/renzojohnson "renzojohnson (1 commits)")

---

Tags

phpemailmailguntransactional emailemail-apimailgun-api

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/renzojohnson-mailgun-api/health.svg)

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

###  Alternatives

[slm/mail

Integration of various email service providers in the Laminas\\Mail

108741.5k1](/packages/slm-mail)[henrique-borba/php-sieve-manager

A modern (started in 2022) PHP library for the ManageSieve protocol (RFC5804) to create/edit Sieve scripts (RFC5228). Used by Cypht Webmail.

28137.9k3](/packages/henrique-borba-php-sieve-manager)[hafael/azure-mailer-driver

Supercharge your Laravel or Symfony app with Microsoft Azure Communication Services (ACS)! Effortlessly add email, chat, voice, video, and telephony-over-IP for next-level communication. 🚀

15122.2k](/packages/hafael-azure-mailer-driver)[azine/mailgunwebhooks-bundle

Symfony2 Bundle to easily capture feedback from mailgun.com via their provided webhooks

104.2k](/packages/azine-mailgunwebhooks-bundle)[naif/php-cpanel-email

Manage cPanel Email Addresses

211.3k](/packages/naif-php-cpanel-email)

PHPackages © 2026

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