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);
Note: Email address validation v3 has been depreciated in favor of v4.
$mailgun->EmailValidation()->validate('[email protected]');
$mailgun->EmailValidationV4()->validate('[email protected]');
$mailgun->events()->get('example.com');
$parameters = [
'from' => '[email protected]',
'to' => '[email protected]',
'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 (this one is outdated).
$message = new Swift_Message('Mail Subject');
$message->setFrom(['[email protected]' => 'Example Inc']);
$message->setTo(['user0gmail.com' => 'User 0', '[email protected]' => 'User 1']);
// $message->setBcc('[email protected]'); Do not do this, BCC will be visible for all receipients if you do.
$message->setCc('[email protected]');
$messageBody = 'Look at the <b>fancy</b> HTML body.';
$message->setBody($messageBody, 'text/html');
// We need all "tos". Incluce the BCC here.
$to = ['[email protected]', 'user0gmail.com', '[email protected]', '[email protected]']
// Send the message
$mailgun->messages()->sendMime('example.com', $to, $message->toString(), []);
Below in an example how to create a Mime message with Symfony Mailer.
$email = (new \Symfony\Component\Mime\Email())
->from('[email protected]')
->to('[email protected]')
->cc('[email protected]')
->bcc('[email protected]')
->replyTo('[email protected]')
//->priority('some priority')
->subject('Time for Symfony Mailer!')
->text('Sending emails is fun again!')
->html('<p>Your awesome text!</p>');
$mailgun->messages()->sendMime($domain, $recipients, $email->getHtmlBody(), $params);
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('[email protected]')"];
$description = 'Test route';
$mailgun->routes()->create($expression, $actions, $description);
$expression = "match_recipient('.*@gmail.com')";
$actions = ["forward('[email protected]')"];
$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', '[email protected]');
$mailgun->suppressions()->bounces()->create('example.com', '[email protected]');
$mailgun->suppressions()->bounces()->delete('example.com', '[email protected]');
$mailgun->suppressions()->bounces()->deleteAll('example.com');
$mailgun->suppressions()->complaints()->index('example.com');
$mailgun->suppressions()->complaints()->show('example.com', '[email protected]');
$mailgun->suppressions()->complaints()->create('example.com', '[email protected]');
$mailgun->suppressions()->complaints()->delete('example.com', '[email protected]');
$mailgun->suppressions()->complaints()->deleteAll('example.com');
$mailgun->suppressions()->unsubscribes()->index('example.com');
$mailgun->suppressions()->unsubscribes()->show('example.com', '[email protected]');
$mailgun->suppressions()->unsubscribes()->create('example.com', '[email protected]');
$mailgun->suppressions()->unsubscribes()->delete('example.com', '[email protected]');
$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);