I am trying to send notifications through Firebase, but it is not working. I just want to send to all my registered users with their Firebase ID stored in MySQL.
EDIT:
Here is the code below.
<?php $message="test message"; $title="Test Title";
$path_to_fcm='https://fcm.googleapis.com/fcm/send';
$server_key="AIzaSyxxxxxxxxxxxxxxxxXxxxsk";
$con = mysqli_connect('localhost','username','passs','db');
$email ="hii"; $sql = "SELECT * FROM users WHERE email = '$email'";
$res = mysqli_fetch_array(mysqli_query($con,$sql)); $key=
$res['token']; $headers=array(
'Authorization:key='.$server_key,
'Content-Type:application/json'
); $fields=array('to'=>$key,'notification'=>array('title'=>$title,'body'=>$message));
$payload=json_encode($fields); $curl_session=curl_init(); curl_setopt($curl_session,CURLOPT_URL,$path_to_fcm);
curl_setopt($curl_session,CURLOPT_POST,true);
curl_setopt($curl_session,CURLOPT_HTTPHEADER,$headers);
curl_setopt($curl_session,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl_session,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($curl_session,CURLOPT_IPRESOLVE,CURL_IPRESOLVE_V4);
curl_setopt($curl_session,CURLOPT_POSTFIELDS,$payload);
$result=curl_exec($curl_session); curl_close($curl_session);
mysqli_close($con);
?>
It's working fine, but it's only for sending to a single user. What I need is for sending to multiple users.