[ 'name' => $email->getFromName(), 'email' => $email->getFromEmail() ], 'bcc' => [], 'subject' => $email->getSubject(), 'htmlContent' => $email->getHtmlContent() ] ; foreach($usersArray 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) ]); } }