_config['api_key']; $headers = array( 'Authorization' => 'key=' . $api_key, 'Content-Type' => 'application/json', ); // Set notification $notification = []; $notification['title'] = $message->getSubject(); $notification['body'] = $message->getContent(); foreach($tokens as $i => $token) { $data = json_encode(array( 'registration_ids' => [$token], 'notification' => $notification, 'priority' => 'normal', 'data' => $message->getData() ?: new stdClass, )); $result = \FileHandler::getRemoteResource($url, $data, 5, 'POST', 'application/json', $headers); if($result) { $error = json_decode($result)->error_code; if($error) { $message->addError('FCM error code: '. $error); $status = false; } } else { $message->addError('FCM return empty response.'); $status = false; } } return $status; } }