0) { // result found $intercom= mysql_fetch_array($result1); $id = $intercom['id']; $result2 = mysql_query("SELECT `appid` FROM `client_table` WHERE `intercom_id` = '$id' and `active` = 1"); $clients = array(); while(($row = mysql_fetch_assoc($result2))) { $clients[] = $row['appid']; } $message_result = send_notification($title,date("d/m H:i",strtotime('+2 hours'))." ".$message, $clients); echo date("Y-m-d H:i:s",strtotime('+2 hours'))." ".$message_result; $insert_query = "INSERT INTO `messageboard_table`(`intercom_id`, `user`, `message`) VALUES ($id,'Intercom','$title')"; $insert_result = mysql_query($insert_query); } else { // failed to insert row $response["success"] = 0; $response["message"] = "Oops! Intercom not found on database"; // echoing JSON response echo json_encode($response); } } else { // required field is missing $response["success"] = 0; $response["message"] = "Required field(s) is missing"; // echoing JSON response echo json_encode($response); } function send_notification ($title, $body, $tokens) { $url = 'https://fcm.googleapis.com/fcm/send'; $priority="high"; $notification= array('title' => $title,'body' => $body ); $fields = array( 'registration_ids' => $tokens, 'notification' => $notification ); require_once __DIR__ . '/db_config.php'; $server_key = FB_SERVER_KEY; $headers = array( 'Authorization:key='.$server_key, 'Content-Type: application/json' ); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); // echo json_encode($fields); $result = curl_exec($ch); echo curl_error($ch); if ($result === FALSE) { die('Curl failed: ' . curl_error($ch)); } curl_close($ch); return $result; } ?>