Send Emails Using Mandrill

Author - Pawandeep Kaur
15.05.2019
|
0 Comments
||

How to Send Emails Using Mandrill

Mandrill is a transactional email platform which was built by Mailchimp. It is used for sending the personalized, one-to-one e-commerce emails, and automated transactional emails like password resets, order confirmations, and welcome messages

Steps:
1. Firstly we need to create the mandrill account. You can create your account by visiting this url “https://mandrill.com/signup/”.
2. Now, add your Mandrill account to your Mailchimp account, by following these steps:
a) Click your profile name and choose Account.
b) Then click Transactional tab.
c)Click Add Mandrill.
d) Then choose any monthly plan by clicking “Purchase Monthly Transactional Email Plan”.

3. Now download the zip file of mandrill library and place it in your project.
“https://mandrillapp.com/api/docs/index.php.html”
4. To use the mandrill API functionality, you have to include the library and instantiate the Mandrill class.

require_once (mandrill-api-php/src/Mandrill.php);   // include mandrill library
   	 $mandrill = new Mandrill(‘API_KEY’);
Create API KEY:
Go to SETTING->SMTP & API Info:


Now, On click of “+ New API Key” button, you can create a key.

5. Now,we will display how we send bulk emails using a template:
a. Firstly, we create a template:

        $name = ‘Sample';  //required
        $from_email = 'xxx@xxx.com'; //Default Sender Email
        $from_name = Test User; //Default Sender Name
       $subject = ’Sample Template subject’;’
       $code=“<html><head><title>*|subject|*</title></head><body> 
                     <div> Sample Code </div></body></html>”;
      $result = $mandrill->templates->add($name,$from_email, $from_name, $subject,$code);

b. Send the mail by using this template:

$msg = array(
     'subject' => 'Sample Template Email',
     'from_email' => xxx@xxx.com',
     'from_name' =>Test User,
     'to' => array(
             array(
               	 'email' => 'recipient.email1@example.com',
               	 'name' => 'Recipient Name1',
                	 'type' => 'to'
             ),
     	array(
               	'email' => 'recipient.email2@example.com',
              	'name' => 'Recipient Name2',
                	'type' => 'to'
            ),
  ),   						
                         'merge' => true,
 'merge_language' => 'mailchimp'     		
 );
$content = array(
   		array(
   			'name' => subject,
   			'content'=>‘Mandrill Email Template’
   		)		
 );
                        $async = false;    
              $result=$mandrill->messages->sendTemplate(‘Sample’, $content, $msg , $async);
}catch(Mandrill_Error $e) {
   	// Mandrill errors are thrown as exceptions
    echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage();
    throw $e;
                       }   		

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *