Skip to content

Commit e632e1b

Browse files
committed
Add MailChimp subscribe email address example
1 parent 88f62fb commit e632e1b

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
require '../src/Curl.class.php';
3+
4+
5+
define('MAILCHIMP_API_KEY', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXX');
6+
define('MAILCHIMP_BASE_URL', 'https://' . explode('-', MAILCHIMP_API_KEY)['1'] . '.api.mailchimp.com/2.0/');
7+
8+
9+
$curl = new Curl();
10+
$curl->get(MAILCHIMP_BASE_URL . '/lists/list.json', array(
11+
'apikey' => MAILCHIMP_API_KEY,
12+
));
13+
14+
if ($curl->response->total === 0) {
15+
echo 'No lists found';
16+
exit;
17+
}
18+
19+
$lists = $curl->response->data;
20+
$list = $lists['0'];
21+
22+
$curl->post(MAILCHIMP_BASE_URL . '/lists/subscribe.format', array(
23+
'apikey' => MAILCHIMP_API_KEY,
24+
'id' => $list->id,
25+
'email' => array(
26+
'email' => 'user@example.com',
27+
),
28+
));
29+
30+
if ($curl->error) {
31+
echo $curl->response->name . ': ' . $curl->response->error . "\n";
32+
}
33+
else {
34+
echo 'Subscribed ' . $curl->response->email . '.' . "\n";
35+
}

0 commit comments

Comments
 (0)