<?php
/**
This Example shows how to run a Batch Subscribe on a List using the MCAPI.php
class and do some basic error checking or handle the return values.
**/
require_once 'inc/MCAPI.class.php';
require_once 'inc/config.inc.php'; //contains apikey
$api = new MCAPI($apikey);
$batch[] = array('EMAIL'=>$my_email, 'FNAME'=>'Joe', 'INTERESTS'=>'Water,Air'); $batch[] = array('EMAIL'=>$boss_man_email, 'FNAME'=>'Me', 'LNAME'=>'Chimp');
$optin = true; //yes, send optin emails
$up_exist = true; // yes, update currently subscribed users
$replace_int = false; // no, add interest, don't replace
$vals = $api->listBatchSubscribe($listId,$batch,$optin, $up_exist, $replace_int);
if ($api->errorCode){
echo "Batch Subscribe failed!\n"; echo "code:".$api->errorCode."\n"; echo "msg :".$api->errorMessage."\n"; } else {
echo "success:".$vals['success_count']."\n"; echo "errors:".$vals['error_count']."\n"; foreach($vals['errors'] as $val){
echo $val['email_address']. " failed\n"; echo "code:".$val['code']."\n"; echo "msg :".$val['message']."\n"; }}
?>
<?php
/**
This Example shows how to use the XML-RPC service to Batch Subscribe many emails
to each of your Lists and do some basic error checking.
Note that we are using the PEAR XML-RPC client and recommend others do as well.
Realize that these emails are bogus and being generated - you should not do
that, especially if you turn on the opt-in email.
**/
require_once 'XML/RPC2/Client.php';
require_once 'inc/config.inc.php';
try {
$lists = $client->lists($apikey);
foreach ($lists as $list){
echo "\n----[".$list['id']." - ".$list['name']."]----\n"; for($i = 0; $i < 20; $i++){
$batch[] = array("EMAIL"=>$list['id'].'_'.$i.'@example.com'); }
/**
Note that there is a limit to the number of addresses that can be batch
subscribed. Here we are using 20, which should be fine. We recommend you
not attempt to add more than 5000-10,000 addresses per call to
*/
$result = $client->listBatchSubscribe($apikey, $list['id'], $batch, false, false, false);
echo "Good : ".$result['success_count']."\n"; echo "Errors: ".$result['error_count']."\n"; foreach($result['errors'] as $err){
echo $err['code'].' - '.$err['message']."\n"; echo "\t".$err['row']['EMAIL']."\n"; }
}
} catch (XML_RPC2_FaultException $e){
echo $e->getFaultCode()." : ".$e->getFaultString()."\n"; }
?>