This is the Mailgun PHP SDK. This SDK contains methods for easily interacting with the Mailgun API. Below are examples for utilizing the SDK!
Installation
-----
To install the SDK, you need to be using Composer in your project. If you aren't using Composer yet, it's really simple! Here's how to install composer and the Mailgun SDK.
Next, require Composer's autoloader to automatically load the Mailgun SDK:
```PHP
require 'vendor/autoload.php';
```
Usage
-----
Using the SDK is rather simple, if you're already familiar with our API. If not, no problem... Just know that the classes follow the API endpoints. So when you're reviewing our documentation, the endpoints are expressed as a class.
Here's an example for sending a message:
```php
# First, instantiate the client with your API credentials and domain.
You've sent your first message, awesome! Let's move on to more advanced scenarios.
#### Message Builder
Message Builder makes creating your messages really intuitive. If you despise arrays, or your workflow is better off defining each part of the MIME separately, use this!
```php
# First, instantiate the client with your API credentials and domain.
$mgClient = new MailgunClient("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org");
# Next, instantiate a Message Builder object on the Messages API endpoint.
$message->setSubject("A message from the PHP SDK using Message Builder!");
# Define the body of the message.
$message->setTextBody("This is the text body of the message!");
# Finally, send the message.
$message->sendMessage();
```
#### Batch Sending
Batch sending allows you to submit up to 1,000 messages per API call. This is the best way to send a large amount of messages as quickly as possible. In the example below, we'll use the MessageBuilder object to create a message.
```php
# First, instantiate the client with your API credentials and domain.
$mgClient = new MailgunClient("key-3ax6xnjp29jd6fds4gc373sgvjxteol0", "samples.mailgun.org");
# Next, instantiate a Batch Message object on the Messages API endpoint.
# (note: The Batch Message object automatically includes a Message Builder object)