다음 튜토리얼을 사용하여 캠페인을 만들고 PHP를 사용하여 MailChimp에서 이메일을 보내고 있습니다.Mailchimp 오류 : 잘못된 요청 - 캠페인 준비가되지 않았습니다.
https://isabelcastillo.com/create-send-mailchimp-campaign-api-3
내 코드 조각은
여기오류 내가 API 키, 목록 ID, 템플릿 ID 등 여전히 난 점점 오전 오류를 포함하여 모든 값을 업데이트 한
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 = '[email protected]';
$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;
}
}
}
입니다된다 오브젝트
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 )
메일 침팬지를 체크했는데 거기에 캠페인이 생성되었지만 초안으로 저장되었습니다. 여기
내가 캠페인을 만들 수 있어요API 로그가 https://drive.google.com/file/d/0BwIWuJmCDI1vNHgtVm9TQm1FMVU/view?usp=drivesdk
아래 링크를 클릭하여 볼 수 있습니다 내 API 로그이며, 캠페인 템플릿을 설정하지만 난 이메일을 보낼 수 없습니다. 내 도메인은 또한 지침을 사용하여 Mailchimp를 통해 확인되고 인증됩니다. 해결책을 확인하고 제안하십시오.
Hello Joel. 제안 해 주셔서 감사합니다. 나는 메일 침팬지에 연락했고 그들은 나에게 똑같은 것을 말했고 문제는 내가 사용하고 있던 이메일 템플릿과 관련되어 있었다. 전자 메일에서 모든 내용을 삭제 한 다음 확인을 위해 더미 텍스트를 추가 했으므로 문제가 없습니다. 도와 줘서 고마워. –
@OptimumCreative 도와 드리겠습니다! –