首页 > 解决方案 > 使用 PHP 在 Mailchimp api 3.0 中禁用双重选择

问题描述

我在这里和其他几个网站上阅读了多个主题。他们都说要禁用双重选择,我需要将用户注册为“订阅”。那没有用。这是我的代码:

 $data = [
 'email'     => $_GET['email'],
 'status'    => 'subscribed'
 ];
 syncMailchimp($data);
static function syncMailchimp($data) {
        $apiKey = 'XXXXXXXXXXX-us3';
        $listId = 'XXXXXXXXXX';

        $memberId = md5(strtolower($data['email']));
        $dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
        $url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listId . '/members/' . $memberId;

        $json = json_encode([
                'email_address' => $data['email'],
                'status'        => $data['status'], // "subscribed","unsubscribed","cleaned","pending"
        ]);

        $ch = curl_init($url);

        curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
        $result = curl_exec($ch);
        $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        curl_close($ch);
        return $httpCode;


}

当我尝试从帐户中禁用双重选择加入时,它显示为灰色并且不允许我取消选中它: 在此处输入图像描述

如果你有任何想法,我很想听听。谢谢!

标签: phpmailchimp

解决方案


It sounds like that MailChimp Account might be in a compliance state. Sometimes this can require that lists be double opt-in mode. I would log into that account and look for any notifications in the top top-right-hand corner that would indicate that this is the case.

Hope this helps out!


推荐阅读