Mandrill API to send Mails with Templates also dynamic content using PHP
Mandrill API to send Mails with Templates also dynamic content using PHP
Mandrill: The fastest way to deliver email Mandrill.com
Follow these steps to start your Mandrill app.
Goto click here https://mandrillapp.com/ create your mandrill account.
After creating mandrill account Create app get API keys like bellow pic.
Above code placed the API key and details sender, receiver emails.
Create a template:
Mandrill: The fastest way to deliver email Mandrill.com
Follow these steps to start your Mandrill app.
Goto click here https://mandrillapp.com/ create your mandrill account.
After creating mandrill account Create app get API keys like bellow pic.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Add Mandrill API Key */ | |
$api_key = 'Boh-3DftryhjuLNH4564ssdfgsadrbd4r5r645sg'; | |
$email_id= "suneel2you@gmail.com"; // recipient emailaddress | |
$subject = 'Welcome mail from Mandrill'; //subject | |
$from = 's*****@example.com'; | |
$uri = 'https://mandrillapp.com/api/1.0/messages/send-template.json'; | |
$content_text = strip_tags($content); | |
$use_name = "suneel"; | |
$postString = '{ "key": "' . $api_key . '","template_name": | |
"First","template_content": [{"name": "header","content":"' . $use_name . '"}], "message": {"html": "' . $content . '", "text": "' . $content_text . '", "subject": "' . $subject . '", | |
"from_email": "' . $from . '", "from_name": "' . $from . '", "to": [ | |
{ "email": "' . $email_id . '", "name": "' . $email_id . '" } ], | |
"track_opens": true, | |
"track_clicks": true, "auto_text": true, "url_strip_qs": true, "preserve_recipients": true }, "async": false }'; | |
$ch = curl_init(); | |
//print_r($postString);exit; | |
curl_setopt($ch, CURLOPT_URL, $uri); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true ); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true ); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_POST, true); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $postString); | |
$result = curl_exec($ch); | |
print_r($result); | |
?> |
Above code placed the API key and details sender, receiver emails.
Create a template:
Running the php code your localhost
http://localhost/mandrill.php
After successfully running php file dispaly output Gmail
Mandrill app Dashboard activity page like this.
ThankYou,