简单的php函数,可使用Mandrill发送电子邮件

问题描述:

通过Mailchimp的Mandrill服务(使用API​​)发送电子邮件的最简单方法是什么.

What is the easiest way to send an email via Mailchimp's Mandrill service (using the API).

这是发送方法: https://mandrillapp.com/api/docs /messages.html#method=send

这里是API包装器: https://bitbucket .org/mailchimp/mandrill-api-php/src/fe07e22a703314a51f1ab0804018ed32286a9504/src?at = master

Here's the API wrapper: https://bitbucket.org/mailchimp/mandrill-api-php/src/fe07e22a703314a51f1ab0804018ed32286a9504/src?at=master

但是我不知道如何制作一个通过Mandrill发送和发送电子邮件的PHP函数.

But I can't figure out how to make an PHP function that will send and email via Mandrill.

任何人都可以帮忙吗?

我们还有一个适用于PHP的官方API包装器,该包装器 Packagist (为您包装Mandrill API)

We also have an official API wrapper for PHP, which is available on Bitbucket or via Packagist, which wraps the Mandrill API for you.

如果您的Mandrill API密钥存储为环境变量,这是一个使用模板进行发送的简单示例,其中包含一些合并变量和元数据:

If your Mandrill API key is stored as an environment variable, here's a simple example of sending using a template, with some merge variables and metadata:

<?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' => 'you@yourdomain.com',
    'html' => '<p>this is a test message with Mandrill\'s PHP wrapper!.</p>',
    'to' => array(array('email' => 'recipient1@domain.com', 'name' => 'Recipient 1')),
    'merge_vars' => array(array(
        'rcpt' => 'recipient1@domain.com',
        '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));

?>