-1

I am trying to check if an e-mail address a user enters already is in the list of subscribers or not.

This is what I have tried so far:

<?php
$apikey = 'apikey';
$list_id = 'listid';
$chunk_size = 4096; //in bytes
$url = 'http://us14.api.mailchimp.com/export/1.0/list?apikey='.$apikey.'&id='.$list_id;

/** a more robust client can be built using fsockopen **/
$handle = @fopen($url,'r');
if (!$handle) {
  echo "failed to access url\n";
} else {
  $i = 0;
  $header = array();
  while (!feof($handle)) {
    $buffer = fgets($handle, $chunk_size);
    if (trim($buffer)!=''){
      $obj = json_decode($buffer);
      if ($i==0){
        //store the header row
        $header = $obj;
      } else {
        //echo, write to a file, queue a job, etc.
        echo $obj[0];
      }
      $i++;
    }
  }
  fclose($handle);
}
?>

This will return all email subscribers. I am trying to narrow it down to the specific e-mail the user entered, but I am stuck and don't know how to do it?

waka
  • 3,362
  • 9
  • 35
  • 54
Savan Paun
  • 1,723
  • 2
  • 16
  • 24

1 Answers1

0
/** a more robust client can be built using fsockopen **/
$handle = @fopen($url,'r');
if (!$handle) {
  echo "failed to access url\n";
} else {
  $i = 0;
  $header = array();
  while (!feof($handle)) {
    $buffer = fgets($handle, $chunk_size);
    if (trim($buffer)!=''){
      $obj = json_decode($buffer);
      if ($i==0){
        //store the header row
        $header = $obj;
      } else {
        //echo, write to a file, queue a job, etc.
        if ($obj[0] == "myemail@gmail.com") { echo "XXXXXXX";} else { }
      }
      $i++;
    }
  }
  fclose($handle);
}
?>