Looking For Anything Specific?

Send Push notification using php(FCM)


Here is our new topic. Sending push notification using FCM

FCM is a new version of the 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.

Example of how to send push notification to android/iOS using php

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

PHP script to send push notification
    $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));
Above is a simple example of how to send push notification using PHP(FCM)

Tags: send push notification to multiple devices php fcm,send push notification to all devices php fcm,send push notification to ios using php fcm,fcm push notification with image in php,send push notification to android using php firebase,how to send image in push notification android using php,firebase web push notification php,implement push notification using php codeigniter