【发布时间】:2015-08-16 08:08:35
【问题描述】:
使用来自 DrewM 的 MailChimp API v2 包装器,我尝试使用大约 700 行的列表批量订阅来更新我的列表。
当处理多达 500 行时,我没有任何问题,但在那之后,列表似乎更新正常,但没有返回任何内容。
我以为我已经从这篇类似的帖子中找到了答案 [Mailchimp Batch Subscribe 2.0 Returns False on 500+ records (PHP)
问题依旧
我也按照建议尝试了超时,(脚本似乎运行了大约 10 秒)
<?php
//loop through the recordset and create the batch array
while(!$rscontacts->atEnd()) {
$merge_vars = array(
'FNAME'=> $rscontacts->getColumnVal("FirstName"),
'LNAME'=> $rscontacts->getColumnVal("LastName"),
'CONTACTID'=> $rscontacts->getColumnVal("ContactID"),
'CONTTYPE'=> $rscontacts->getColumnVal("ContactTypeID"),
'ACTIVE'=> $rscontacts->getColumnVal("Active"),
'INMAILING'=> $rscontacts->getColumnVal("InMailing")
);
$batch[] = array(
'email' => array('email' => $rscontacts->getColumnVal("EmailAddress1")),
"email_type" => "html", // optional, for the email type option (html or text)
'merge_vars' => $merge_vars
);
$rscontacts->moveNext();
}
$rscontacts->moveFirst(); //return RS to first record
//print_r($batch);
?>
...
<?php
set_time_limit(0);
$api = 'xxx';
$mcListId = 'xxx';
$MailChimp = new \Drewm\MailChimp(xxx);
$retval = $MailChimp->call("lists/batch-subscribe", array(
"id" => $mcListId,
"batch" => $batch,
"double_optin" => false,
"update_existing" => true,
"replace_interests" => true // optional, flag to determine whether we replace the interest groups with the updated groups provided, or we add the provided groups to the member's interest groups
));
if ($retval === false) {
echo "Mailchimp API returned false";
}
?>
<?php echo $retval ['add_count'].' Records added'; ?><br>
<?php echo $retval ['update_count'].' Records updated'; ?><br>
<?php echo $retval ['error_count'].' Errors Found'; ?><br>
[1]: https://stackoverflow.com/questions/29082925/mailchimp-batch-subscribe-2-0-returns-false-on-500-records-php
【问题讨论】:
标签: php api batch-processing mailchimp