Nowadays, Email marketing is increasing rapidly and become one of the most demanding services in the internet business. In email marketing, emails are one of the most powerful communication media which create a strong bond between companies and their clients.

Sending emails to a large number of clients are one of the most difficult and challenging tasks for the users. They need a powerful medium to send emails to their clients.

Keeping in mind such requirement of users for sending emails, we are creating a blog to Send Email via Mandrill API Using PHP.

We are going to integrate Mandrill API/SMTP services for sending personalized and one-to-one e-commerce emails.

It can also be used to send automated transactional emails like password resets, order confirmations, and welcome messages.

Watch the live demo or download code from the link given below

We have introduced a very effective and powerful online email management sevice name MailGet. Using MailGet you can easily send bulk emails through Mandrill and manage your emails at very low cost.

Steps to configure Mandrill API in an application: –

Step 1: – Download the latest Mandrill API library .zip folder.
Step 2: – Extract the downloaded .zip folder.
Step 3: – Create a lib folder in the root folder, copy & paste all the files available in the src folder of extracted zip folder.
Step 4: – Create index.php and paste the PHP code given below in it.


Provide an interactive user interface to insert important information like sender’s email, reciever’s email, message etc. These information will be stored in an array which will further passed to the Mandrill API library and send emails.

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Send Email via Mandrill API Using PHP</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script src="js/jquery.js"></script>

// include Mandrill library file
include ("lib/Mandrill.php");

// Passing Mandrill API key in the library
$mandrill = new Mandrill('<-- Mandrill API-Key -->');
$sen_name = "";
$sen_email = "";
$rec_name = "";
$rec_email = "";
$email_type = "";
$email_sub = "";
$msg_type = "";
$box_msg = "";
$message = array();
$to = array();
if (isset($_POST['sen_name'])) {
$sen_name = $_POST['sen_name'];
if (isset($_POST['sen_email'])) {
$sen_email = $_POST['sen_email'];
if (isset($_POST['rec_name'])) {
$rec_name = $_POST['rec_name'];
if (isset($_POST['rec_email'])) {
$rec_email = $_POST['rec_email'];
if (isset($_POST['email_type'])) {
$email_type = $_POST['email_type'];
if (isset($_POST['email_sub'])) {
$email_sub = $_POST['email_sub'];
if (isset($_POST['msg_type'])) {
$msg_type = $_POST['msg_type'];
if (isset($_POST['box_msg'])) {
$box_msg = $_POST['box_msg'];
$to[] = array(
'email' => $rec_email,
'name' => $rec_name,
'type' => $email_type
$message['subject'] = $email_sub;
$message[$msg_type] = $box_msg;
$message['from_email'] = $sen_email;
$message['from_name'] = $sen_name;
$message['to'] = $to;
if(isset($to[0]['email']) && $to[0]['email'] !== ""){
$result = $mandrill->messages->send($message);
$status = $result[0]['status'];

<div id="main">
<h1>Send Email via Mandrill API Using PHP</h1>
<div id="login">
<h2>Message Box</h2>
<form action="" method="POST">
<h3>From : </h3>
<label>Sender's Name (Optional) : </label> <input type="text" name="" class="" placeholder="Enter Sender's Name"/>
<label>Sender's Email Address : </label> <input type="email" name="sen_email" class="sen_email" placeholder="Enter Sender's Email Address"/>
<h3>To : </h3>
<label>Receiver's Name (Optional) : </label> <input type="text" name="rec_name" class="" placeholder="Enter Receiver's Name"/>
<label>Receiver's Email Address : </label> <input type="email" name="rec_email" class="rec_email" placeholder="Enter Reciever's Email Address"/>
<label>Email Type : </label>
<input type="radio" name="email_type" value="to" checked="checked" /><label> Default </label>
<input type="radio" name="email_type" value="cc"/><label> cc </label>
<input type="radio" name="email_type" value="bcc"/><label> bcc </label>
<label>Subject : </label>
<input type="text" name="email_sub" class="" placeholder="Subject"/>
<label>Message : </label>
<input type="radio" name="msg_type" value="text" checked="checked"/><label>text</label>
<input type="radio" name="msg_type" value="html"/><label>html</label>
<textarea name="box_msg" rows="10" cols="30">Write your message here...</textarea>
<input type="submit" value="Check" id="submit"/>

<div id="note">
if (isset($status)){
if($status == "sent") {
echo "<script>alert('Congratulations!!! Your Email has been sent successfully!!!')</script>";
} elseif($status == "rejected") {
echo "<script>alert('Sorry!!! Some error occurs, Please try again.')</script>";
jQuery(document).ready(function() {
jQuery("#submit").click(function() {
var sen_email = jQuery('.sen_email').val();
var rec_email = jQuery('.rec_email').val();
if (sen_email == "") {
alert('Sender's Email Address cannot be empty.');
if (rec_email == "") {
alert('Receiver's Email Address cannot be empty.');

Step 5: – Create style.css file and paste the css code given below in it.


Includes basic styling of HTML elements.


@import url(;

margin:50px auto;
background-color: #FEFFED;
border-radius: 10px 10px 0 0;
margin: -10px -40px;
padding: 15px;
border-bottom:1px solid #ccc;
margin: 10px -40px;
margin-bottom: 30px;
float: left;
border-radius: 10px;
border: 2px solid #ccc;
padding: 10px 40px 25px;
margin-top: 70px;
padding: 10px;
margin-top: 8px;
border: 1px solid #ccc;
padding-left: 5px;
font-size: 16px;
width: 100%;
color: white;
border: 2px solid #FFCB00;
padding: 10px;
border-radius: 5px;
margin-bottom: 15px;
width: 100%;
div#main h1 {
margin-left: -80px;

Conclusion :

Hope you have enjoyed reading the above post and will definitely integrate and use Mandrill API for sending emails. Always keep in touch with us for more interesting blogs. You can send us your feedback and share your experience about the blog in the space given below 🙂