Question

I use Mandrill plugin for Codeigniter.

I created HTML template through Mandrill account, named fess1 with merge tag FNAME, after I published it.

Example:

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

Now I try to send mail from codeigniter like:

 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);
    }

The result:

I get the mail, based on fess1 template, but with the tag *|FNAME|*.

Sounds like Mandrill didn't recognize the merge tag.

I used mandrill->messages_send_template but since my template stored into Mandrill account I have no clue what I need to provide for $template_content.

So I wrote dummy info there.

Did I miss something?

Thank you,

[EDIT]

From logs this is what I send:

{
    "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"
}
Was it helpful?

Solution

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', 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top