我正在尝试以编程方式将用户添加到MailChimp列表中(因此他是我将发送的任何电子邮件的订阅者)。我确实有专业版的MailChimp for WordPress插件。
有没有一种方法可以动态地向列表中添加和删除用户(电子邮件和三个字段)?似乎有API(http://developer.mc4wp.com/),但我没有找到这样做的函数。
有吗?
使用mc4wp_get_api
函数获取MailChimp for WordPress API的实例。然后调用subscribe()
函数,在列表中添加一封电子邮件:
$list_id = "2341ca4321";
$email = "subscriber@email.com";
$api = mc4wp_get_api();
$api->subscribe($list_id, $email);
subscribe()
函数返回一个布尔值。此返回值只是报告订阅请求是否成功。如果用户已经在列表中,将返回false
- 登录MailChimp时,可以在列表
Settings > List name and campaign defaults > List ID
下找到$list_id
include('/MailChimp.php');
$MailChimp = new 'DrewM'MailChimp'MailChimp("API-KEY");
$result = $MailChimp->get('lists');
$list_id = 'a0123a45f'; // List Key
$result = $MailChimp->post("lists/$list_id/members", [
'email_address' => test@test.com,
'status' => 'subscribed',
'merge_fields' => array('FNAME'=>'test', 'LNAME'=>'tester'),
]);