Firebase Notification not received on device when sent via cURL/PHP

Try to add { priority : high }

$fields = array
(
    'to'            => "cUxd-iTVVWo:APA*****kQTuqJ5RREKhhlJjm27NCuVfUn5APg3lBFqh-YWjgx*****iOpAQeLB14CzM2YTwIJo_75jzCmbFLKj0_zpKSHvAEbmJz*****BBezGJIng-N4H-cAD6ahY7mQNYZtEJLAIE",
    'data'          => $msg,
    'priority'      =>'high'
);

There were two issues:

  1. I needed to include a notification section in the payload instead of data
  2. Somehow the payload wasn't being formatted properly by PHP.

In the end I used the PHP function shell_exec() to do a cURL request over SSH instead. This isn't ideal but it got the job done.

Example code:

shell_exec('curl -X POST --header "Authorization: key=<key here>" --header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"to\":\"'.$to.'\",\"priority\":\"high\",\"notification\":{\"body\": \"'.stripslashes($message).'\"}}"');

From the Firebase documentation you have the choice of using either data or notification in the message payload. But when you use data, you have the responsibility of handling the receipt of the notification yourself. In other words it will not be sent straight away to your app client. You handle it in the didReceiveRemoteNotification: for ios and onMessageReceived() in case of Android.

If however you use notification in the payload, firebase will send the message straight away to your client App.

That is why you will not receive the message(in case you used data) even if your curl request tells you it has succeeded in making the request.