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.
What is Mailgun-PHP Library?
Crafting reliable email functionality for PHP applications is made simple and efficient with the Mailgun-PHP library. This open-source tool, released under the widely-adopted MIT License, provides developers with a straightforward and powerful SDK for integrating seamless email capabilities. It is specifically engineered for high reliability in handling critical transactional emails, ensuring your application's messages are delivered consistently. By offering robust support for the standard SMTP protocol, the Mailgun-PHP library simplifies the process of both sending and receiving email messages directly from your PHP codebase, streamlining development and reducing complexity.
Beyond its foundational reliability, the Mailgun-PHP library stands out for its comprehensive and developer-friendly feature set, designed for both stability and time-efficiency. It empowers developers to not only create and send email messages but also to implement advanced functionalities such as detailed email message tracking, parsing incoming emails, and managing message forwarding and storage. Key capabilities include sending emails to multiple recipients, attaching files and images, validating email addresses for list hygiene, and handling batch message operations. Additional utilities like pagination support for managing large data sets and tools for creating bounce handling logic make this library an exceptionally complete solution for building sophisticated, scalable, and dependable email communication features directly into any PHP application.
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/psr7You can also download it from GitHub and manually install it with ease.
Email Message Sending via PHP API
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.
How to 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.
How to 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.