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