function AddSubscriberToList($emailAddress, $listIDs, $subscriberKey = null) { $newSub = new ET_Subscriber(); $newSub->authStub = $this; $lists = array(); foreach ($listIDs as $key => $value) { $lists[] = array("ID" => $value); } //if (is_string($emailAddress)) { $newSub->props = array("EmailAddress" => $emailAddress, "Lists" => $lists); if ($subscriberKey != null) { $newSub->props['SubscriberKey'] = $subscriberKey; } /*} else if (is_array($emailAddress)) { $newSub->props = array(); for ($i = 0; $i < count($emailAddress); $i++) { $copyLists = array(); foreach ($lists as $k => $v) { $NewProps = array(); foreach($v as $prop => $value) { $NewProps[$prop] = $value; } $copyLists[$k] = $NewProps; } $p = array("EmailAddress" => $emailAddress[$i], "Lists" => $copyLists); if (is_array($subscriberKey) && $subscriberKey[$i] != null) { $p['SubscriberKey'] = $subscriberKey[$i]; } $newSub->props[] = $p; } }*/ // Try to add the subscriber $postResponse = $newSub->post(); if ($postResponse->status == false) { // If the subscriber already exists in the account then we need to do an update. // Update Subscriber On List if ($postResponse->results[0]->ErrorCode == "12014") { $patchResponse = $newSub->patch(); return $patchResponse; } } return $postResponse; }
$postResponse = $postContent->post(); print_r('Post Status: ' . ($postResponse->status ? 'true' : 'false') . "\n"); print 'Code: ' . $postResponse->code . "\n"; print 'Message: ' . $postResponse->message . "\n"; print 'Results Length: ' . count($postResponse->results) . "\n"; print 'Results: ' . "\n"; print_r($postResponse->results); print "\n---------------\n"; if ($postResponse->status) { $newListID = $postResponse->results[0]->NewID; // Create Subscriber on List print "Create Subscriber on List \n"; $subCreate = new ET_Subscriber(); $subCreate->authStub = $myclient; $subCreate->props = array("EmailAddress" => $SubscriberTestEmail, "Lists" => array("ID" => $newListID)); $postResult = $subCreate->post(); print_r('Post Status: ' . ($postResult->status ? 'true' : 'false') . "\n"); print 'Code: ' . $postResult->code . "\n"; print 'Message: ' . $postResult->message . "\n"; print 'Results Length: ' . count($postResult->results) . "\n"; print 'Results: ' . "\n"; print_r($postResult->results); print "\n---------------\n"; if (!$postResult->status) { // If the subscriber already exists in the account then we need to do an update. // Update Subscriber On List if ($postResult->results[0]->ErrorCode == "12014") { // Update Subscriber to add to List print "Update Subscriber to add to List \n"; $subPatch = new ET_Subscriber(); $subPatch->authStub = $myclient;