2013-01-23 40 views
25

के साथ एक ईमेल भेजने के लिए सरल php फ़ंक्शन Mailchimp की मंड्रिल सेवा (API का उपयोग करके) के माध्यम से ईमेल भेजने का सबसे आसान तरीका क्या है। https://bitbucket.org/mailchimp/mandrill-api-php/src/fe07e22a703314a51f1ab0804018ed32286a9504/src?at=masterमंडलिल

लेकिन मैं समझ नहीं कैसे एक PHP समारोह का बंदर के माध्यम से भेजने के लिए और ईमेल मिलेगी कि बनाने के लिए: https://mandrillapp.com/api/docs/messages.html#method=send

यहाँ एपीआई आवरण है:

यहाँ भेजने विधि है।

क्या कोई मदद कर सकता है?

उत्तर

59

हम भी PHP के लिए एक अधिकारी एपीआई आवरण है, जो उपलब्ध on Bitbucket या Packagist के माध्यम से है, जो आप के लिए प्रकार का बंदर एपीआई लपेटता है।

अपने प्रकार का बंदर API कुंजी एक वातावरण चर के रूप में जमा है, तो यहां एक टेम्पलेट का उपयोग कर भेजने का एक सरल उदाहरण है, के साथ कुछ चर और मेटाडाटा विलय: https://bitbucket.org/mailchimp/mandrill-api-php

:

<?php 
require 'Mandrill.php'; 

$mandrill = new Mandrill(); 

// If are not using environment variables to specific your API key, use: 
// $mandrill = new Mandrill("YOUR_API_KEY") 

$message = array(
    'subject' => 'Test message', 
    'from_email' => '[email protected]', 
    'html' => '<p>this is a test message with Mandrill\'s PHP wrapper!.</p>', 
    'to' => array(array('email' => '[email protected]', 'name' => 'Recipient 1')), 
    'merge_vars' => array(array(
     'rcpt' => '[email protected]', 
     'vars' => 
     array(
      array(
       'name' => 'FIRSTNAME', 
       'content' => 'Recipient 1 first name'), 
      array(
       'name' => 'LASTNAME', 
       'content' => 'Last name') 
    )))); 

$template_name = 'Stationary'; 

$template_content = array(
    array(
     'name' => 'main', 
     'content' => 'Hi *|FIRSTNAME|* *|LASTNAME|*, thanks for signing up.'), 
    array(
     'name' => 'footer', 
     'content' => 'Copyright 2012.') 

); 

print_r($mandrill->messages->sendTemplate($template_name, $template_content, $message)); 

?> 
+6

भविष्य के उपयोगकर्ताओं के लिए एक नोट के रूप में, आपको आउटबाउंड -> टेम्पलेट मेनू के नीचे मिले मंडल में एक टेम्पलेट बनाना होगा निम्नानुसार न्यूनतम HTML:

टेम्पलेट स्लॉग स्टेशनरी से मेल खाना चाहिए। टेम्पलेट्स पर और जानकारी यहां मिल सकती है http://help.mandrill.com/entries/21694286-How-do-I-add- गतिशील- सामग्री- उपयोग करने योग्य-regions-in-my-template- – Treemonkey

21

मंड्रिल HTTP POST उनके सभी API विधियों के लिए अनुरोध लेते हैं, और वे आपके इनपुट को JSON स्ट्रिंग के रूप में लेते हैं। ईमेल भेजने का मूल उदाहरण यहां दिया गया है। यह cURL का उपयोग करता HTTP अनुरोध करने के लिए:

$uri = 'https://mandrillapp.com/api/1.0/messages/send.json'; 

$postString = '{ 
"key": "YOUR KEY HERE", 
"message": { 
    "html": "this is the emails html content", 
    "text": "this is the emails text content", 
    "subject": "this is the subject", 
    "from_email": "[email protected]", 
    "from_name": "John", 
    "to": [ 
     { 
      "email": "[email protected]", 
      "name": "Bob" 
     } 
    ], 
    "headers": { 

    }, 
    "track_opens": true, 
    "track_clicks": true, 
    "auto_text": true, 
    "url_strip_qs": true, 
    "preserve_recipients": true, 

    "merge": true, 
    "global_merge_vars": [ 

    ], 
    "merge_vars": [ 

    ], 
    "tags": [ 

    ], 
    "google_analytics_domains": [ 

    ], 
    "google_analytics_campaign": "...", 
    "metadata": [ 

    ], 
    "recipient_metadata": [ 

    ], 
    "attachments": [ 

    ] 
}, 
"async": false 
}'; 

$ch = curl_init(); 
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); 

echo $result; 
+1

आप ZF2 और ZF1 में यह परीक्षण किया था? एफवाईआई काम नहीं किया। – YumYumYum

+0

सीसी, कई ईमेल पते के लिए बीसीसी काम नहीं कर रहा है – YumYumYum

+0

मेरे लिए काम किया! –

5
// Simply Send Email Via Mandrill... 

require_once 'Mandrill.php'; 
$mandrill = new Mandrill($apikey); 

$message = new stdClass(); 
$message->html = "html message"; 
$message->text = "text body"; 
$message->subject = "email subject"; 
$message->from_email = "[email protected]"; 
$message->from_name = "From Name"; 
$message->to = array(array("email" => "[email protected]")); 
$message->track_opens = true; 

$response = $mandrill->messages->send($message); 
2

यह कोड का सबसे बुनियादी टुकड़ा है जो मैं आपको दे सकता हूं, मैं इसे क्लाइंट के लिए कुछ सेकंड पहले तैयार करता हूं और यह चिकनी काम कर रहा है।

require_once 'path/to/your/mandrill/file/Mandrill.php'; 
try { 
    $mandrill = new Mandrill('your-API-key'); 
    $message = array(
     'html' => $htmlMessage, 
     'subject' => $subject, 
     'from_email' => $fromEmail, 
     'from_name' => $fromName, 
     'to' => array(
      array(
       'email' => $toEmail, 
       'name' => $toName, 
       'type' => 'to' 
      ) 
     ) 
    ); 
    $result = $mandrill->messages->send($message); 
    print_r($result); 
} catch(Mandrill_Error $e) { 
    echo 'A mandrill error occurred: ' . get_class($e) . ' - ' . $e->getMessage(); 
    throw $e; 
} 

इसके अलावा मेटा डेटा हेडर की तरह अधिक विकल्पों के लिए उनके भेजने विधि जाँच, संलग्नक आदि https://mandrillapp.com/api/docs/messages.php.html#method-send

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^