一个合理的方法是使用 mailchimp 的 REST api。您正在寻找的方法是listMemberInfo。 Mailchimp 为 api 提供了一个 PHP 包装器,您可以找到下载 here。安装包装器后,您将需要您的 api 密钥和您在帐户中找到的列表密钥。
当然你也可以 curl api 端点
https://<dc>.api.mailchimp.com/2.0/
您将 api 密钥、列表和电子邮件数据作为 json 编码数组发布的位置。
基本上,查询 api 的函数可能如下所示,例如,我们将 us2 作为适当的数据中心(您可以在 api 键中的破折号后找到它):
function queryMailChimp($email){
$url = 'https://us2.api.mailchimp.com/2.0/lists/member-info.json';
$arguments = json_encode(array('apikey'=>'your_api_key','id'=>'your_list_id','emails'=>array('email'=$email)));
$contentType ='Content-Type: application/json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($contentType));
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $arguments);
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
curl_close($ch);
return array('status' => $status, 'header' => $header, 'response' => json_decode($body, true), 'request'=>array('url'=>$url,'content'=>$contentType,'data'=>$arguments));
}