0

我为 Codeigniter 使用 Mandrill 插件。

发布后,我通过 Mandrill 帐户创建了 HTML 模板,fess1并以 merge 标签命名FNAME

例子:

 ...
<p>
  <span>Hi *|FNAME|*,<br></span>
</p>
....

现在我尝试从 codeigniter 发送邮件,例如:

 private  function sendMailMandrill($owner_name,$business_name,$owner_email){

        $message = array('dest_mail' => $owner_email);   

        $message['to'] = array(array('email' => 'mim@wefi.com'));

        $mergeVars[] = array(
            'rcpt' => array(array('email' => 'mim@wefi.com')),
            'vars' => array(
                array(
                    'name' => 'FNAME',
                    'content' => 'Fessy'
                )
            )
        );

        $message['merge'] = true;
        $template_name = 'fess1';        
        $template_content = array(  // I don't know what I need to provide here, left it empty
                                 array(
                                 'name' => 'example name',
                                 'content' => 'example content'
                                 )
                ); 
        $message['merge_vars'] = $mergeVars;       

        return $this->mandrill->messages_send_template($template_name, $template_content, $message);
    }

结果:

我收到邮件,基于fess1模板,但带有标签*|FNAME|*

听起来 Mandrill 无法识别合并标签。

我使用过mandrill->messages_send_template,但由于我的模板存储在 Mandrill 帐户中,我不知道我需要提供什么$template_content

所以我在那里写了虚拟信息。

我错过了什么?

谢谢,

[编辑]

从日志中,这是我发送的:

{
    "template_name": "fess1",
    "template_content": [
        {
            "name": "example name",
            "content": "example content"
        }
    ],
    "message": {
        "owner_name": "עידו",
        "business_name": "פלאפל מוסקו",
        "dest_mail": "maxim@wifi.com",
        "to": [
            {
                "email": "maxim@wifi.com"
            }
        ],
        "merge": "true",
        "merge_vars": [
            {
                "rcpt": [
                    {
                        "email": "maxim@wifi.com"
                    }
                ],
                "vars": [
                    {
                        "name": "FNAME",
                        "content": "Fessy"
                    }
                ]
            }
        ]
    },
    "key": "xxxxxxxxxxxxxxxx"
}
4

1 回答 1

2

You can provide blank information for the template_content parameter. That parameter allows you to use mc:edit regions in your template. It is a required parameter, but a blank array will suffice if all of the content is in your template in Mandrill.

As for whether the merge_vars were recognized, the first thing we recommend is inspecting the API Logs for your account (Settings > API Logs) since that will show you the JSON that Mandrill received. You can then compare that to the expected JSON format from the Mandrill API docs: https://mandrillapp.com/api/docs/messages.JSON.html#method=send-template

It looks like your arrays may not be nested as expected. Once you view the JSON that's being generated as compared with the expected format, you can also view the PHP documentation for the Mandrill PHP client. It may not be identical to the CodeIgniter plugin, but should give you an idea of how the merge_vars parameter would be structured in PHP: https://mandrillapp.com/api/docs/messages.php.html

In mergeVars you created array instead key:value. Change it to:

'rcpt' => 'mim@wefi.com', 
于 2013-11-12T18:20:39.840 回答