Mailchimp API (PHP) - 您的营销活动尚未准备好发送

Mailchimp API (PHP) - Your Campaign is not ready to send

我在使用 PHP 使用 Mailchimp API 时遇到问题。

当我 运行 编写代码时,这是我得到的错误:

{
    "type": "http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/",
    "title": "Bad Request",
    "status": 400,
    "detail": "Your Campaign is not ready to send.",
    "instance": "46235d29-6a67-4d55-800d-a95e2dc7273f"
}

我知道为什么活动还没有准备好发送,正如您在这张图片中看到的,详细信息已填写,但未保存:

这是我正在尝试的代码 运行:

<?php
require '../vendor/autoload.php';
$apiKey = 'API ';

$mailchimp = new \MailchimpAPI\Mailchimp($apiKey);

$list_created = $mailchimp->lists()->post([
  'name' => 'Lista Monday',
  'contact' => [
    'company' => 'Test Company Monday',
    'address1' => 'Monday address 1',
    'city' => 'Monday City',
    'state' => 'Monday State',
    'zip' => '227560',
    'country' => 'Romania'
  ],
  'permission_reminder' => 'test',
  'campaign_defaults' => [
    'from_name' => 'Anjus Parsay',
    'from_email' => 'FROM EMAIL',
    'subject' => 'Monday Email',
    'language' => 'English'
  ],
  'email_type_option' => false
]);

$list_id = json_decode($list_created->getBody(), true)['id'];

$email = "EMAIL ";

$addedUser = $mailchimp->lists($list_id)->members()->post([
    'email_address' => $email,
    'status' => 'subscribed'
]);

//1. Create the template
$template_content = file_get_contents("http://widevisiondesign.com/anjus/mailchimp/src/testTemplate.html");

$template = $mailchimp->templates()->post([
'name' => 'testTemplateHTML',
'html' => $template_content
]);

$template_id = json_decode($template->getBody(), true)['id'];

//2. Create a campaign
$campaign = $mailchimp->campaigns()->post([
'type' => 'regular',
'recipients' => [
'list_id' => $list_id
],
'settings' => [
'title' => 'Monday',
'subject_line' => 'Monday - Sunday',
'from_name' => 'NAME NAME',
'to_name' => 'test',
'preview_text' => 'Preview text - Monday',
'template_id' => $template_id
]
]);

$campaign_id = json_decode($campaign->getBody(), true)['id'];

$sent = $mailchimp->campaigns($campaign_id)->send([$email], 'plaintext')->getBody();

print_r($sent);

?>

谢谢!

根据您提供的代码和屏幕截图,我想到了以下几点:

  1. 您是否验证并验证了您的电子邮件地址?如果不是,您需要验证您的电子邮件地址的域。转到您的 Mailchimp 仪表板,单击帐户 > 设置 > 域 > 验证域。
  2. 然后添加您的域,按照说明进行验证和身份验证。
  3. 如果您愿意,可以在实际发送电子邮件之前拨打 API 电话以获取清单。核对表给出了成功和错误说明,说明在实际发送电子邮件之前需要做什么。
  4. 很抱歉,如果这看起来有些不妥,但您真的提供了您的电子邮件地址来代替 'FROM EMAIL' 占位符吗?从代码来看,你似乎设置了 from_name 的名称,但没有设置 from_email.