Product

The PHP SDK: The first of many official Mailgun SDKs

The PHP SDK allows you to easily interact with our API by yanking all the boiler plate code necessary to interact with an HTTP web service. Read more –

PUBLISHED ON

PUBLISHED ON

Today, we’re happy to announce that for PHP developers, it’s even easier to send messages with Mailgun! Over the past few weeks, we’ve been busy working on SDKs for the Mailgun API. The SDK allows you to easily interact with our API by yanking all the boiler plate code necessary to interact with an HTTP web service. Today, we’re releasing the PHP version of the SDK. Additional languages will follow soon.

For those not familiar with an SDK, let’s first review what’s required to send a message using the standard HTTP CURL library for PHP.

Sending a message with CURL:

The above will send a message using the Mailgun API, however, there’s a lot of code there that, while important, is complicated, and unless you’re a CURL expert, could be rather confusing.

Using our new SDK, we’ve managed to reduce the amount of code required to just a few lines.

Sending a message with Mailgun PHP SDK:

Obtaining Logs with the Mailgun PHP SDK:

All HTTP actions return a response object which you can easily interact with.

If you’d like to get started using the SDK today, the code is available as a public repo on Github (mailgun-php). You’ll find ways to do everything you can do with the Mailgun API. For additional usage examples, check out the README within the repository. We didn’t stop there though… We’ve created a few utilities within the SDK.

Message Builder

Creating an array of parameters can be difficult for some code implementations, so we’ve included a class that allows you to make method calls that automatically build a properly formed array of message parameters.

Sending a message with Mailgun PHP SDK + Message Builder:

For a list of all available functions, check out the list on Github.

Batch Message

In addition to Message Builder, we have Batch Message. This class allows you to build a message and submit a template message in batches, up to 1,000 recipients per post. The benefit of using this class is that the recipients tally is monitored and will automatically submit the message to the endpoint when you’ve added the 1,000th recipient. This means you can build your message and begin iterating through your database. Forget about sending the message, the SDK will keep track of posting to the API when necessary.

Sending a message with Mailgun PHP SDK + Batch Message:

As you can see, Batch Message actually extends Message Builder. All functions available in Message Builder are available in Batch Message. Check out the full documentation on Github.

Opt-In Handler

Finally, we have built a simple double opt-in handler to help you generate unique opt-in links. The opt-in handler also uses our free address validation service to validate the accuracy of the email addresses.

The typical flow for using this class would be as follows: Recipient Requests Subscribe -> [Validate Recipient Address] -> [Generate Opt In Link] -> [Email Recipient Opt In Link] Recipient Clicks Opt In Link -> [Validate Opt In Link] -> [Subscribe User] -> [Send final confirmation]

It is best to use this class for your website subscription forms, so you’ll need a web server accessible to the internet to handle the validation link click.

Let us know what you think. Is there something else you’d like to see in the SDK? Or something you love. We’d appreciate your feedback!

Happy sending,

The Mailgunners

Sign Up

It's easy to get started. And it's free.

See what you can accomplish with the world’s best email delivery platform.

Related readings

What are SMTP commands and what do you need to know about them?

Why do we need SMTP commands and what do they do? Well, we use SMTP (Simple Mail Transfer Protocol) commands to communicate with email servers. These commands are...

Read more

What is SMTP and how does it work?

SMTP, though a pillar of email delivery, often gets lost in the jumble of tech terms and acronyms. But if you're ready to send impactful emails, this is one of those acronyms that...

Read more

Forrester TEI study reveals Sinch Mailgun ROI and outcomes

When an enterprise starts working with Sinch Mailgun, what’s the financial impact that choice has on the business? It’s a good question – but not exactly an easy one to answer...

Read more

Popular posts

Email inbox.

Build Laravel 10 email authentication with Mailgun and Digital Ocean

When it was first released, Laravel version 5.7 added a new capability to verify user’s emails. If you’ve ever run php artisan make:auth within a Laravel app you’ll know the...

Read more

Mailgun statistics.

Sending email using the Mailgun PHP API

It’s been a while since the Mailgun PHP SDK came around, and we’ve seen lots of changes: new functionalities, new integrations built on top, new API endpoints…yet the core of PHP...

Read more

Statistics on deliverability.

Here’s everything you need to know about DNS blocklists

The word “blocklist” can almost seem like something out of a movie – a little dramatic, silly, and a little unreal. Unfortunately, in the real world, blocklists are definitely something you...

Read more

See what you can accomplish with the world's best email delivery platform. It's easy to get started.Let's get sending
CTA icon