public function batchSubscribe($listId, array $subscribers)
    {
        $batchResults = [];
        // as suggested in MailChimp API docs, we send multiple smaller requests instead of a bigger one
        $subscriberChunks = array_chunk($subscribers, self::SUBSCRIBER_BATCH_SIZE);
        foreach ($subscriberChunks as $subscriberChunk) {
            $Batch = $this->mailchimp->new_batch();
            foreach ($subscriberChunk as $index => $newsubscribers) {
                $subscriberHash = $this->mailchimp->subscriberHash($newsubscribers->getEmail());
                $Batch->put("op$index", "lists/$listId/members/$subscriberHash", array_merge(
                    $newsubscribers->formatMailChimp(),
                    ['status' => 'subscribed']
                ));
            }
            $Batch->execute();
            $currentBatch = $Batch->check_status();
            array_push($batchResults, $currentBatch);
        }
        return $batchResults;
    }
public function batchSubscribe($listId, array $subscribers)
    {
        $batchResults = [];
        // as suggested in MailChimp API docs, we send multiple smaller requests instead of a bigger one
        $subscriberChunks = array_chunk($subscribers, self::SUBSCRIBER_BATCH_SIZE);
        foreach ($subscriberChunks as $subscriberChunk) {
            $Batch = $this->mailchimp->new_batch();
            foreach ($subscriberChunk as $index => $newsubscribers) {
                $subscriberHash = $this->mailchimp->subscriberHash($newsubscribers->getEmail());
                $Batch->put("op$index", "lists/$listId/members/$subscriberHash", array_merge(
                    $newsubscribers->formatMailChimp(),
                    ['status' => 'subscribed']
                ));
            }
            $Batch->execute();
            $currentBatch = $Batch->check_status();
            array_push($batchResults, $currentBatch);
        }
        return $batchResults;
    }
public function batchSubscribe ( $ listId , array $ subscribers ) { $ batchResults = [ ] ; // as suggested in MailChimp API docs, we send multiple smaller requests instead of a bigger one $ subscriberChunks = array_chunk ( $ subscribers , self :: SUBSCRIBER_BATCH_SIZE ) ; foreach ( $ subscriberChunks as $ subscriberChunk ) { $ Batch = $ this -> mailchimp -> new_batch ( ) ; foreach ( $ subscriberChunk as $ index => $ newsubscribers ) { $ subscriberHash = $ this -> mailchimp -> subscriberHash ( $ newsubscribers -> getEmail ( ) ) ; $ Batch -> put ( "op$index" , "lists/$listId/members/$subscriberHash" , array_merge ( $ newsubscribers -> formatMailChimp ( ) , [ 'status' => 'subscribed' ] ) ) ; } $ Batch -> execute ( ) ; $ currentBatch = $ Batch -> check_status ( ) ; array_push ( $ batchResults , $ currentBatch ) ; } return $ batchResults ; }
Subscribe a batch of Subscriber to a list
@param string $listId
@param array $subscribers
@return array $batchIds
Subscribe a batch of Subscriber to a list