bonsaicode / mailgun
MailGun API Wrapper to easily send messages using MailGun's API including support for attachments and inline/embedded images.
1.1.0
2026-11-14 17:18 UTC
Requires
- php: >=7.1
- ext-curl: *
- ext-fileinfo: *
- ext-json: *
Requires (Dev)
- phpunit/phpunit: ^9.6 || ^10.5 || ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
MailGun API Wrapper. Provides wrapper to easily send messages using MailGun's API including support for attachments and inline/embedded images.
Dependencies:
You must have a mailgun account.
This class assumes a MAILGUN associative array constant is defined:
const MAILGUN = [
'API_KEY' => 'your mailgun api key',
'BASE_URL' => 'https://api.mailgun.net/v3/', # or https://api.eu.mailgun.net/v3/
'DEFAULT_DOMAIN' => 'your domain name', # your default domain to send from, which can be overridden per message with 'domain'
'WEBHOOK_SIGNING_KEY' => 'your HTTP webhook signing key' # optional, used by verifyWebhookSignature(); falls back to API_KEY
];
Requirements
- PHP 7.1 or higher, with the curl, fileinfo and json extensions
Installation
To install the package, run the following command in the console:
$ composer require "bonsaicode/mailgun"
Usage
see examples/MailGunTest.php
# Verify a webhook; reject ones older than 5 minutes to limit replays
if( BonsaiCode\MailGun::verifyWebhookSignature( $_POST['token'], $_POST['timestamp'], $_POST['signature'], 300 ) ) { ... }
sendMessage() waits at most 10 seconds to connect and 60 seconds in total (override with options connectTimeout and timeout).