通过php

时间:2017-12-18 13:19:31

标签: php mailchimp-api-v3.0

我正在尝试检查用户输入的电子邮件地址是否在订阅者列表中。

这是我到目前为止所尝试的:

<?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);
}
?>

这将返回所有电子邮件订阅者。我试图将其缩小到用户输入的特定电子邮件,但我卡住了,不知道该怎么做?

1 个答案:

答案 0 :(得分: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);
}
?>