first you have to save the tokens for every single device you want to send notification to, I've saved them on a table call "FCM_TOKEN", then retrieve tokens (I'm using PDO) and send them using while loop like this:
while($row=$statement->fetch(PDO::FETCH_BOTH))
{
$key = $row['Fcm_Token'];
$headers = array(
'Authorization:key=' .$server_key,
'Content-Type:application/json');
$fields = array('to'=>$key,
'notification'=>array('title'=>$titulo, 'body'=>$mensaje,
'click_action'=>'com.example.witch.gtslsac_app_1_TARGET_NOTIFICATION'
));
$playload=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, $playload);
$result = curl_exec($curl_session);
echo $result;
}
Don't forget to close session curl_close($curl_session);
this worked just fine for me.