public function addSubscriber($email, $name, $customFields = array(), $resubscribe = true, $listId = null)
{
// set list ID
$listId = empty($listId) ? $this->getListId() : $listId;
// set parameters
$parameters['EmailAddress'] = (string) $email;
$parameters['Name'] = (string) $name;
$parameters['Resubscribe'] = (bool) $resubscribe;
// set custom fields if any were found
if (!empty($customFields)) {
// fetch all existing custom fields
//$currentFields = (array) $this->getCustomFields($listId);
// loop the custom fields, build a new array
//foreach($currentFields as $key => $field) $currentFields[$key] = $field['name'];
// loop the fields
foreach ($customFields as $key => $value) {
// check if this field already exists; if not, add it.
//if(!in_array($key, $currentFields)) $this->createCustomField($key, 'text', null, $listId);
// add it to the list of field values
$parameters['CustomFields'][] = array('Key' => $key, 'Value' => $value);
}
}
// make the call
$this->doCall('subscribers/' . $listId, $parameters, 'POST');
// if we made it here, return true
return true;
}