This page will document the API classes and ways to properly use the API. These resources will eventually move to the official documentation at https://documentation.mailgun.com.
Other relevant documentation pages might be:
$mailgun->domains()->index();$mailgun->domains()->show('example.com');$mailgun->domains()->verify('example.com');$mailgun->domains()->create('new.example.com', 'password', 'disable', '*');$mailgun->domains()->delete('example.com');$mailgun->domains()->credentials('example.com');$mailgun->domains()->createCredential('example.com', 'login', 'password');$mailgun->domains()->updateCredential('example.com', 'login', 'password');$mailgun->domains()->deleteCredential('example.com', 'login');$mailgun->domains()->connection('example.com');$mailgun->domains()->updateConnection('example.com', true, false);$mailgun->events()->get('example.com');$parameters = [
'from' => 'bob@example.com',
'to' => 'sally@example.com',
'subject' => 'The PHP SDK is awesome!',
'text' => 'It is so simple to send a message.'
];
$mailgun->messages()->send('example.com', $parameters);Below in an example how to create a Mime message with SwiftMailer.
$message = new Swift_Message('Mail Subject');
$message->setFrom(['from@exemple.com' => 'Example Inc']);
$message->setTo(['user0gmail.com' => 'User 0', 'user1@hotmail.com' => 'User 1']);
// $message->setBcc('admin@example.com'); Do not do this, BCC will be visible for all receipients if you do.
$message->setCc('invoice@example.com');
$messageBody = 'Look at the <b>fancy</b> HTML body.';
$message->setBody($messageBody, 'text/html');
// We need all "tos". Incluce the BCC here.
$to = ['admin@example.com', 'user0gmail.com', 'user1@hotmail.com', 'invoice@example.com']
// Send the message
$mailgun->messages()->sendMime('example.com', $to, $message->toString(), []);If you got an URL to a stored message you may get the details by:
$url = // ...
$mailgun->messages()->show($url);$mailgun->routes()->index();Get a route by its ID
$mailgun->routes()->show(4711);$expression = "match_recipient('.*@gmail.com')";
$actions = ["forward('alice@example.com')"];
$description = 'Test route';
$mailgun->routes()->create($expression, $actions, $description);$expression = "match_recipient('.*@gmail.com')";
$actions = ["forward('alice@example.com')"];
$description = 'Test route';
$mailgun->routes()->update(4711, $expression, $actions, $description);$mailgun->routes()->delete(4711);$mailgun->stats()->total('example.com');$mailgun->stats()->all('example.com');The suppression API consists of 3 parts; Bounce, Complaint and Unsubscribe.
$mailgun->suppressions()->bounces()->index('example.com');$mailgun->suppressions()->bounces()->show('example.com', 'alice@gmail.com');$mailgun->suppressions()->bounces()->create('example.com', 'alice@gmail.com');$mailgun->suppressions()->bounces()->delete('example.com', 'alice@gmail.com');$mailgun->suppressions()->bounces()->deleteAll('example.com');$mailgun->suppressions()->complaints()->index('example.com');$mailgun->suppressions()->complaints()->show('example.com', 'alice@gmail.com');$mailgun->suppressions()->complaints()->create('example.com', 'alice@gmail.com');$mailgun->suppressions()->complaints()->delete('example.com', 'alice@gmail.com');$mailgun->suppressions()->complaints()->deleteAll('example.com');$mailgun->suppressions()->unsubscribes()->index('example.com');$mailgun->suppressions()->unsubscribes()->show('example.com', 'alice@gmail.com');$mailgun->suppressions()->unsubscribes()->create('example.com', 'alice@gmail.com');$mailgun->suppressions()->unsubscribes()->delete('example.com', 'alice@gmail.com');$mailgun->suppressions()->unsubscribes()->deleteAll('example.com');$mailgun->tags()->index('example.com');$mailgun->tags()->show('example.com', 'foo');$mailgun->tags()->update('example.com', 'foo', 'description');$mailgun->tags()->stats('example.com', 'foo');$mailgun->tags()->delete('example.com', 'foo');$timestamp = $_POST['timestamp'];
$token = $_POST['token'];
$signature = $_POST['signature'];
$mailgun = Mailgun::create('my_api_key');
$valid = $mailgun->webhooks()->verifyWebhookSignature($timestamp, $token, $signature);
if (!$valid) {
// Create a 403 response
exit();
}
// The signature is valid$mailgun->webhooks()->index('example.com');$mailgun->webhooks()->show('example.com', 'accept');$mailgun->webhooks()->create('example.com', 'opened', [ 'https://www.exmple.com/webhook' ]);$mailgun->webhooks()->update('example.com', 4711, [ 'https://www.exmple.com/webhook' ]);$mailgun->webhooks()->delete('example.com', 4711);