【问题标题】:What the template_content should be in case that template itself has no need for it (eg template has no mc:edit)?如果模板本身不需要它(例如模板没有 mc:edit),那么 template_content 应该是什么?
【发布时间】:2021-09-06 04:53:58
【问题描述】:

我用 mailchimp/transactional 替换了 mandrill/mandrill 包。我还有一个名为 MYTEMPLATE-001-GR 的模板,带有 mergevar name

我尝试使用该模板发送电子邮件:

<?php
require_once '/path/to/MailchimpTransactional/vendor/autoload.php';

$mailchimp = new MailchimpTransactional\ApiClient();
$mailchimp->setApiKey('YOUR_API_KEY');

$message = [
  'subject' => 'Lorem Ipsum',
  'from_email' => 'user@example.com',
  'from_name'  => 'Example User',
  'to'   => 'user@example.com'
  'global_merge_vars' => ['name'=>'Chuck Norris'],
  'track_opens' => true,
  'track_clicks' => true
];

$response = $mailchimp->messages->sendTemplate([
    "template_name" => "MYTEMPLATE-001-GR",
    "template_content" => [[]],
    "message" => $message,
]);
print_r($response);

但响应如下:

"""
HTTP/1.1 500 Internal Server Error\r\n
server: nginx/1.4.6 (Ubuntu)\r\n
date: Tue, 22 Jun 2021 13:51:38 GMT\r\n
content-type: application/json; charset=utf-8\r\n
transfer-encoding: chunked\r\n
access-control-allow-origin: *\r\n
access-control-allow-methods: POST, GET, OPTIONS\r\n
access-control-allow-headers: Content-Type\r\n
access-control-allow-credentials: false\r\n
\r\n
{"status":"error","code":-1,"name":"ValidationError","message":"You must specify a template_content value"}
"""

意思是我应该在template_content 中提供一些值,但我的模板没有输入字段,只是合并变量,因此我不知道在这种情况下需要提供什么值。

以前的版本它只是使用 NULL 作为模板内容值并且工作得很好。你知道如何将调用更改为更高版本吗?

【问题讨论】:

    标签: php mailchimp mandrill


    【解决方案1】:

    在这种情况下,基于 tweettemplate_content 用于 sendTemplate Mandrill APi 调用的 template_content 应包含以下值:

     'template_content'=>[["name"=>'','content'=>'']],
    

    因此您的代码应如下所示:

    require_once '/path/to/MailchimpTransactional/vendor/autoload.php';
    
    $mailchimp = new MailchimpTransactional\ApiClient();
    $mailchimp->setApiKey('YOUR_API_KEY');
    
    $message = [
      'subject' => 'Lorem Ipsum',
      'from_email' => 'user@example.com',
      'from_name'  => 'Example User',
      'to'   => 'user@example.com'
      'global_merge_vars' => ['name'=>'Chuck Norris'],
      'track_opens' => true,
      'track_clicks' => true
    ];
    
    $response = $mailchimp->messages->sendTemplate([
        "template_name" => "MYTEMPLATE-001-GR",
        "template_content"=>[["name"=>'','content'=>'']],
        "message" => $message,
    ]);
    print_r($response);
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-08
      • 1970-01-01
      • 2011-10-05
      • 1970-01-01
      • 2014-11-28
      • 1970-01-01
      相关资源
      最近更新 更多