Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chetansatasiya/aa8143879a3c42f9dea018548aa7e1b3 to your computer and use it in GitHub Desktop.
Save chetansatasiya/aa8143879a3c42f9dea018548aa7e1b3 to your computer and use it in GitHub Desktop.
Get all subscribers emails from a list
<?php
$api_key = 'YOUR API KEY';
$list_id = 'YOUR LIST ID';
$dc = substr($api_key,strpos($api_key,'-')+1); // us5, us8 etc
$args = array(
'headers' => array(
'Authorization' => 'Basic ' . base64_encode( 'user:'. $api_key )
)
);
$response = wp_remote_get( 'https://'.$dc.'.api.mailchimp.com/3.0/lists/'.$list_id.'/members/', $args );
$body = json_decode( wp_remote_retrieve_body( $response ) );
$emails = array();
if ( wp_remote_retrieve_response_code( $response ) == 200 ) {
foreach ( $body->members as $member ) {
if( $member->status != 'subscribed' )
continue;
$emails[] = $member->email_address;
}
print_r( $emails );
} else {
echo '<b>' . wp_remote_retrieve_response_code( $response ) . wp_remote_retrieve_response_message( $response ) . ':</b> ' . $body->detail;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment