如何在mandrill html文本中添加参数?

时间:2014-02-07 17:45:50

标签: mandrill

有没有办法包含mandrill的参数i html部分?

我没有使用模板。

这是我的代码。

 $mandrill = new Mandrill('YOUR_API_KEY');
$message = array(
    'html' => '<p>here is my email</p>',
    'text' => 'Example text content',
    'subject' => 'example subject',
    'from_email' => 'message.from_email@example.com',
    'from_name' => 'Example Name',
    'to' => array(
        array(
            'email' => 'recipient.email@example.com',
            'name' => 'Recipient Name',
            'type' => 'to'
        ),
         array(
            'email' => 'recipient.email@example.com',
            'name' => 'Recipient Name',
            'type' => 'to'
        )
    ),

我想要做的是在html内容中添加一个参数。

 'html' => '<p>here is my email{ param}</p>', // this line

我该怎么做?

由于

1 个答案:

答案 0 :(得分:1)

听起来你正在寻找使用Mandrill合并标签。

您可以将合并标记插入HTML内容,并为每个收件人注入个性化信息。它们可以在* | MERGETAG | *格式的内容中使用,也可以在消息数组中定义“merge_vars”。

以下是他们的文档中的示例:

"message": {
        "global_merge_vars": [
            {
                "name": "var1",
                "content": "Global Value 1"
            }
        ],
        "merge_vars": [
            {
                "rcpt": "emailadress@domain.com",
                "vars": [
                    {
                        "name": "fname",
                        "content": "John"
                    },
                    {
                        "name": "lname",
                        "content": "Smith"
                    }
                ]
            }
        ],

源: http://help.mandrill.com/entries/21678522-How-do-I-use-merge-tags-to-add-dynamic-content-

在测试中,Mandrill实际上支持一些“开箱即用”的合并标签,因此您应该只需将* | EMAIL | *添加到您的HTML内容中,它就会从您的HTML内容中提取该电子邮件地址到阵列。