Send Push notification using php(FCM)

FCM
FCM is a new version of GCM (Google Cloud Messaging) service. It is a cross-platform messaging service, used to send notifications that are displayed to the user. We can use any of three ways to send messages to the client app – single devices, gro…

FCM
FCM is a new version of GCM (Google Cloud Messaging) service. It is a cross-platform messaging service, used to send notifications that are displayed to the user. We can use any of three ways to send messages to the client app – single devices, groups of devices or devices subscribed to topics. It also sends acknowledgments back to the server. We can use FCM for iOS clients, Android clients, Unity clients, web clients and more. FCM is reliable and battery-efficient.

Just copy and paste the code and change the credentials to yours

<?php
    $url = "https://fcm.googleapis.com/fcm/send";
    $token = "your device token";
    $serverKey = 'your server token of FCM project';
    $title = "Notification title";
    $body = "Hello I am from Your php server";
    $notification = array('title' =>$title , 'body' => $body, 'sound' => 'default', 'badge' => '1');
    $arrayToSend = array('to' => $token, 'notification' => $notification,'priority'=>'high');
    $json = json_encode($arrayToSend);
    $headers = array();
    $headers[] = 'Content-Type: application/json';
    $headers[] = 'Authorization: key='. $serverKey;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST,"POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
    curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
    //Send the request
    $response = curl_exec($ch);
    //Close request
    if ($response === FALSE) {
    die('FCM Send Error: ' . curl_error($ch));
    }
    curl_close($ch);
?>

Read More :: https://cmsinstallation.blogspot.com/2019/05/send-push-notification-using-phpfcm.html


Print Share Comment Cite Upload Translate
APA
koshti Rahul | Sciencx (2024-03-29T13:57:56+00:00) » Send Push notification using php(FCM). Retrieved from https://www.scien.cx/2021/04/23/send-push-notification-using-phpfcm/.
MLA
" » Send Push notification using php(FCM)." koshti Rahul | Sciencx - Friday April 23, 2021, https://www.scien.cx/2021/04/23/send-push-notification-using-phpfcm/
HARVARD
koshti Rahul | Sciencx Friday April 23, 2021 » Send Push notification using php(FCM)., viewed 2024-03-29T13:57:56+00:00,<https://www.scien.cx/2021/04/23/send-push-notification-using-phpfcm/>
VANCOUVER
koshti Rahul | Sciencx - » Send Push notification using php(FCM). [Internet]. [Accessed 2024-03-29T13:57:56+00:00]. Available from: https://www.scien.cx/2021/04/23/send-push-notification-using-phpfcm/
CHICAGO
" » Send Push notification using php(FCM)." koshti Rahul | Sciencx - Accessed 2024-03-29T13:57:56+00:00. https://www.scien.cx/2021/04/23/send-push-notification-using-phpfcm/
IEEE
" » Send Push notification using php(FCM)." koshti Rahul | Sciencx [Online]. Available: https://www.scien.cx/2021/04/23/send-push-notification-using-phpfcm/. [Accessed: 2024-03-29T13:57:56+00:00]
rf:citation
» Send Push notification using php(FCM) | koshti Rahul | Sciencx | https://www.scien.cx/2021/04/23/send-push-notification-using-phpfcm/ | 2024-03-29T13:57:56+00:00
https://github.com/addpipe/simple-recorderjs-demo