Mailchimp Error: Bad Request - Your Campaign is not ready to send

Mailchimp Error: Bad Request - Your Campaign is not ready to send

我正在使用以下教程创建活动并使用 Php 在 MailChimp 中发送电子邮件。

https://isabelcastillo.com/create-send-mailchimp-campaign-api-3

我的代码片段是

    require_once('../wp-load.php');

    function isa_mailchimp_api_request( $endpoint, $type = 'POST', $body = '' ) 
    { 
    // Configure -------------------------------------- 
    $api_key = 'API KEY HERE'; // Changed API Key here 
    // STOP Configuring ------------------------------- 
    $core_api_endpoint = 'https://<dc>.api.mailchimp.com/3.0/';
    list(, $datacenter) = explode( '-', $api_key );
    $core_api_endpoint = str_replace( '<dc>', $datacenter, $core_api_endpoint );

    $url = $core_api_endpoint . $endpoint;  
    //print_r($url );

    $request_args = array(
        'method'      => $type,
        'timeout'     => 20,
        'headers'     => array(
            'Content-Type' => 'application/json',
            'Authorization' => 'apikey ' . $api_key
        )
    );

    if ( $body ) {
        $request_args['body'] = json_encode( $body );
    }

    $request = wp_remote_post( $url, $request_args );
    $response = is_wp_error( $request ) ? false : json_decode( wp_remote_retrieve_body( $request ) );


    echo '<pre>';
    print_r($response); 

    return $response;   
    }



    function isa_create_mailchimp_campaign( $list_id, $subject ) {    
    $reply_to   = 'info@newslume.com';
    $from_name  = 'NewsLume';
    $subject= 'Another new test message 14 17'; 
    $campaign_id = ''; 
    $body = array(
        'recipients'    => array('list_id' => $list_id),
        'type'          => 'regular',
        'settings'      => array('subject_line' => $subject,
                                'title' => 'a  test title NewsLUme',
                                'reply_to'      => $reply_to,
                                'from_name'     => $from_name,
                                'use_conversation'=> false,
                                'to_name'=> 'sajid',

                                'auto_footer'=> false,
                                'inline_css'=> false,
                                'auto_tweet'=> false,
                                'drag_and_drop'=> false

                                )
    );

    $create_campaign = isa_mailchimp_api_request( 'campaigns', 'POST', $body ); 

    if ( $create_campaign ) {
        if ( ! empty( $create_campaign->id ) && isset( $create_campaign->status ) && 'save' == $create_campaign->status ) {
            // The campaign id: 
            $campaign_id = $create_campaign->id;
        }
    }

    return $campaign_id ? $campaign_id : false;

}    

function isa_set_mail_campaign_content( $campaign_id, $template_content  ) {
    $set_content = '';
    $set_campaign_content = isa_mailchimp_api_request( "campaigns/$campaign_id/content", 'PUT', $template_content ); 

    if ( $set_campaign_content ) {
        if ( ! empty( $set_campaign_content->html ) ) {
            $set_content = true;
        }
    }               
    return $set_content ? true : false;
}


$list_id='my_list_id_here'; // LIST HERE

$campaign_id = isa_create_mailchimp_campaign( $list_id, $subject );

if ( $campaign_id ) { 
    // Set the content for this campaign 
   $template_content = array( 
        'template' => array( 
                // The id of the template to use. 
                'id' => 47615, // INTEGER   
                'sections'  => array(                     
                    'tst_content' => 'THIS IS THE CONTENT BODY OF MY EMAIL MESSAGE.' 
            )

        )
    );
    $set_campaign_content = isa_set_mail_campaign_content( $campaign_id, $template_content );


    if ( $set_campaign_content ) {

        $send_campaign = isa_mailchimp_api_request( "campaigns/$campaign_id/actions/send", 'POST' ); 
        if ( empty( $send_campaign ) ) { 
            // Campaign was sent! 
        } elseif( isset( $send_campaign->detail ) ) { 
            $error_detail = $send_campaign->detail;

        }

    }

}

我已经更新了所有值,包括 API KEY、列表 ID、模板 ID 等,但我仍然遇到错误

这是错误对象

stdClass Object ( [type] => http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/ [title] => Bad Request [status] => 400 [detail] => Your Campaign is not ready to send. [instance] => 89dc8734-2611-4f3b-a4f7-d18bd181bded )

我查看了 Mail Chimp,在那里创建了活动,但它们保存为草稿。

这是我的 API 日志

API日志可以点击下方link查看 https://drive.google.com/file/d/0BwIWuJmCDI1vNHgtVm9TQm1FMVU/view?usp=drivesdk

我可以创建活动,为活动设置模板,但我无法发送电子邮件。 My Domain 也使用指南通过 Mailchimp 进行了验证和认证。 请检查并提出解决方案

虽然 "Your Campaign is not ready to send" 消息不是很有帮助,但您可以在 MailChimp 本身中查看更详细的消息。编辑 API 创建的草稿,然后导航到最后的确认步骤。您会看到一个清单,其中大部分项目都通过了检查,但也会有一个项目解释了活动失败的原因。

当我尝试重现该问题时,活动发送失败,因为模板中有一些默认占位符文本未更改。由于您发布的代码只设置了一个块的内容,这可能与您遇到的问题相同。

希望对您有所帮助!