gpt4 book ai didi

php - template_content 应该是什么以防模板本身不需要它(例如模板没有 mc :edit)?

转载 作者:行者123 更新时间:2023-12-05 02:41:31 26 4
gpt4 key购买 nike

我用 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 作为模板内容值并且工作得很好。你知道我如何将调用更改为更高版本吗?

最佳答案

在本例中,template_content 基于 tweet sendTemplate Mandrill APi 调用应包含以下值:

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

关于php - template_content 应该是什么以防模板本身不需要它(例如模板没有 mc :edit)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68086202/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com