1. Products
  2.   Email
  3.   PHP
  4.   Mailgun-PHP
 
  

Open Source PHP  Library to Send Email Messages 

Free PHP API for sending email messages in a very straightforward and simple way. It supports creating email messages, email message tracking, receiving emails, forward email messages, storing messages, email validation & so on.

Mailgun-PHP is a very useful PHP library that helps software developers to send email messages in a very straightforward and simple way. It has included supports the standard SMTP protocol and makes it easy for developers to send and receive email messages from their own PHP applications. It offers high reliability as it’s designed to handle transactional emails in a better way. It is open source and released under the MIT License.

The library is very stable and has provided the most simple, time-efficient, and powerful methods for handling email messages. It has included support for several important features such as creating email messages, email message tracking, receiving emails, forward email messages, storing messages, email validation, sending email to multiple users, attach files or images to email messages, pagination support, batch message, create a bounce and many more.

Previous Next

Getting Started with Mailgun-PHP 

The recommended way to install Mailgun-PHP SDK is via Composer, please use the following command for easy installation.

Install Mailgun-PHP via Composer

 $ composer require mailgun/mailgun-php kriswallsmith/buzz nyholm/psr7

You can also download it from GitHub and manually install it with ease.

Email Message Sending via PHP

The open source Mailgun-PHP library enables software developers to generate and send email messages inside their PHP applications. The library has included several important functions and ways for sending email messages, such as send a plain text message via HTTP, sending a message with HTML and text parts, tracking an email message, tag a message, sending a message with inline images, sending a message to multiple users and many more.

Create & Send Mime Email Message via PHP API

# Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain = "YOUR_DOMAIN_NAME";
$params = array(
  'from'    => 'Excited User ',
  'to'      => 'bob@example.com',
  'subject' => 'Hello',
  'text'    => 'Testing some Mailgun awesomness!'
);

# Make the call to the client.
$mgClient->messages()->send($domain, $params);

Email Message Tracking via PHP

Email tracking is a very useful process that gives users the power to know the information about their email message, such as when the recipient receives it, did it get into the inbox or into the spam folder, did the recipient open it or not, did he click on the links or not and so many other information. The open source Mailgun-PHP library has provided complete functionality for tracking email messages from inside their own PHP apps. It store keeps track of every event that happens to every message for a couple of days, such as accepted, rejected, delivered, failed, opened, clicked, and so on.

Track & Download Events via PHP API

 # Include the Autoloader (see "Libraries" for install instructions)
require 'vendor/autoload.php';
use Mailgun\Mailgun;

# Instantiate the client.
$mgClient    = Mailgun::create('PRIVATE_API_KEY', 'https://API_HOSTNAME');
$domain      = 'YOUR_DOMAIN_NAME';
$queryString = array(
    'begin'        => 'Wed, 1 Jan 2020 09:00:00 -0000',
    'ascending'    => 'yes',
    'limit'        =>  25,
    'pretty'       => 'yes',
    'recipient'    => 'bob@example.com'
);

# Issue the call to the client.
$result = $mgClient->events()->get($domain, $queryString);

Forward and Store Email Messages

The open source Mailgun-PHP library allows PHP applications to receive emails through Routes. Routes will accept emails and then perform operations like storing the email temporarily for subsequent retrieval, forwarding the email to a different email address, Posting the data in the email to a URL. The library allows to store the message temporarily for up to 3 days on Mailgun’s servers so that you can retrieve it later as per your needs.

 English