[ 'name' => $fromName, 'email' => $fromEmail ], 'bcc' => [], 'subject' => $subject, 'htmlContent' => $htmlContent ] ; foreach($contactsArray as $user) { $data['bcc'][] = [ 'name' => $userSolver->getUsernameFromArray($user), 'email' => $user['email'] ]; if(count($data['bcc']) == 50) { $this->requestPostEmailViaApi($client, $data); $data['bcc'] = [] ; } } if(count($data['bcc']) > 0) { $this->requestPostEmailViaApi($client, $data); } } public function requestPostEmailViaApi(Client $client, array $data): ResponseInterface { return $client->request('POST', 'https://api.brevo.com/v3/smtp/email', [ 'headers' => [ 'accept' => 'application/json', 'content-type' => 'application/json', 'api-key' => \Yii::$app->parameterBag->get('brevoApiKey'), ], 'body' => json_encode($data) ]); } }