function send($registration_ids, $message) { $fields = array( 'registration_ids' => $registration_ids, 'data' => $message, ); // stop($fields); return sendPushNotification($fields); } function sendPushNotification($fields) { define('FIREBASE_API_KEY', 'AAAA9HYH3yg:APA91bFdlyT3aZc7I48rKHT8bHph3p1tDyoDfoLeAwqdO_CeKwIQa55_VdOiILRvEs4A7XOhaRTBnweI6NkwEjoL68-3o1Yexk2dXjrXj4BfulU39ZeFA-mgjdgbz3jLCKe4038EBjSx'); //firebase server url to send the curl request $url = 'https://fcm.googleapis.com/fcm/send'; //building headers for the request $headers = array( 'Authorization: key=' . FIREBASE_API_KEY , 'Content-Type: application/json' ); //Initializing curl to open a connection $ch = curl_init(); //Setting the curl url curl_setopt($ch, CURLOPT_URL, $url); //setting the method as post curl_setopt($ch, CURLOPT_POST, true); //adding headers curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //disabling ssl support curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //adding the fields in json format curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); //finally executing the curl request $result = curl_exec($ch); if ($result === FALSE) { die('Curl failed: ' . curl_error($ch)); } //Now close the connection curl_close($ch); //and return the result // return $result; render($result);exit; }