2017-03-08 66 views
-1

我有更新的电子邮件订阅特定列表ID,现在我想提取所有的电子邮件ID,并要检查,如果该特定电子邮件ID已经存在与否,并显示消息“电子邮件已经存在”,如果没有再插入邮件黑客中的电子邮件地址。如何显示电子邮件ID列表从邮件黑猩猩API版本3?

+0

可以请你分享一些代码? –

回答

0
<?php 
require_once 'inc/MCAPI.class.php'; 
$api = new MCAPI('[[YOUR_API_KEY]]'); 
$merge_vars = array('FNAME'=>$_POST["fname"], 'LNAME'=>$_POST["lname"]); 


$retval = $api->listSubscribe('[[YOUR_LIST_ID]]', $_POST["email"], $merge_vars, 'html', false, true); 

if ($api->errorCode == 214){ 
echo "<h4>You are already subscribed.</h4>"; 
} else { 
echo "<h4>Thank you, you have been added to our mailing list.</h4>"; 
} 
?> 
+0

参考https://www.sunarlim.com/2014/04/mailchimp-sign-form-php-jquery-ajax/和http://www.codexworld.com/add-subscriber-to-list-mailchimp-api -php/ –

+0

我没有使用邮件黑猩猩类,但我用麦lchimp API卷曲所以我该怎么办,请建议我 –

+0

检查这个http://www.codexworld.com/add-subscriber-to-list-mailchimp- API-PHP /链接 –

0
function mailchimp_subscriber_status($email, $status, $list_id, $api_key, $merge_fields = array('FNAME' => '','LNAME' => '')){ 
    $data = array(
     'apikey'  => $api_key, 
      'email_address' => $email, 
     'status'  => $status, 
     'merge_fields' => $merge_fields 
    ); 

    $mch_api = curl_init(); // initialize cURL connection 

    curl_setopt($mch_api, CURLOPT_URL, 'https://' . substr($api_key,strpos($api_key,'-')+1) . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/' . md5(strtolower($data['email_address']))); 
    //curl_setopt($mch_api, CURLOPT_USERPWD, 'user:' . $api_key); 
    //curl_setopt($mch_api, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); 
    curl_setopt($mch_api, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Basic '.base64_encode('user:'.$api_key))); 
    curl_setopt($mch_api, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0'); 
    curl_setopt($mch_api, CURLOPT_RETURNTRANSFER, true); // return the API response 
    curl_setopt($mch_api, CURLOPT_CUSTOMREQUEST, 'PUT'); // method PUT 
    curl_setopt($mch_api, CURLOPT_TIMEOUT, 10); 
    curl_setopt($mch_api, CURLOPT_POST, true); 
    curl_setopt($mch_api, CURLOPT_SSL_VERIFYPEER, false); 
    curl_setopt($mch_api, CURLOPT_POSTFIELDS, json_encode($data)); // send data in json 

    $result = curl_exec($mch_api); 
    $httpCode=curl_getinfo($mch_api, CURLINFO_HTTP_CODE); 
    //var_dump($httpCode); die; 
    //$json = json_decode($result); 
    //echo $json->{'status'}; die; 
    //var_dump($result); die; 
    return $result; 
} 

我这样做,并添加用户,但现在我要检索的用户列表中,我没有使用邮件黑猩猩类。

0
$httpCode=curl_getinfo($mch_api, CURLINFO_HTTP_CODE); 
if ($httpCode == 200) { 
      $_SESSION['msg'] = '<p style="color: #34A853">You have successfully subscribed to CodexWorld.</p>'; 
     } else { 
      switch ($httpCode) { 
       case 214: 
        $msg = 'You are already subscribed.'; 
        break; 
       default: 
        $msg = 'Some problem occurred, please try again.'; 
        break; 
      } 
      $_SESSION['msg'] = '<p style="color: #EA4335">'.$msg.'</p>'; 
     } 
    }else{ 
     $_SESSION['msg'] = '<p style="color: #EA4335">Please enter valid email address.</p>'; 
    } 
+0

如果错误代码214比电子邮件已经存在需要的方法 –