mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-30 12:14:36 +00:00
Add MailChimp subscribe email address example
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
require '../src/Curl.class.php';
|
||||
|
||||
|
||||
define('MAILCHIMP_API_KEY', 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-XXX');
|
||||
define('MAILCHIMP_BASE_URL', 'https://' . explode('-', MAILCHIMP_API_KEY)['1'] . '.api.mailchimp.com/2.0/');
|
||||
|
||||
|
||||
$curl = new Curl();
|
||||
$curl->get(MAILCHIMP_BASE_URL . '/lists/list.json', array(
|
||||
'apikey' => MAILCHIMP_API_KEY,
|
||||
));
|
||||
|
||||
if ($curl->response->total === 0) {
|
||||
echo 'No lists found';
|
||||
exit;
|
||||
}
|
||||
|
||||
$lists = $curl->response->data;
|
||||
$list = $lists['0'];
|
||||
|
||||
$curl->post(MAILCHIMP_BASE_URL . '/lists/subscribe.format', array(
|
||||
'apikey' => MAILCHIMP_API_KEY,
|
||||
'id' => $list->id,
|
||||
'email' => array(
|
||||
'email' => 'user@example.com',
|
||||
),
|
||||
));
|
||||
|
||||
if ($curl->error) {
|
||||
echo $curl->response->name . ': ' . $curl->response->error . "\n";
|
||||
}
|
||||
else {
|
||||
echo 'Subscribed ' . $curl->response->email . '.' . "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user