Skip to content

Instantly share code, notes, and snippets.

@muddy-28
Created October 15, 2019 17:32
Show Gist options
  • Save muddy-28/34883cae8b25cfb5e4d6c9316927d02a to your computer and use it in GitHub Desktop.
Save muddy-28/34883cae8b25cfb5e4d6c9316927d02a to your computer and use it in GitHub Desktop.
Send Push Notification to Users Using Firebase Messaging Service in PHP. I will show you how to send unlimited free push notifications to your clients using Firebase Cloud Messaging (FCM) in your PHP web application. Push Notifications are clickable messages that come from a website. They are used to show notifications outside the web page conte…
<?php
// Server key from Firebase Console
define( 'API_ACCESS_KEY', 'AAAA----FE6F' );
$data = array("to" => "cNf2---6Vs9",
"notification" => array( "title" => "Eagale Soluions", "body" => "A Code Sharing Company!","icon" => "icon.png", "click_action" => "http://eagalesoft.com"));
$data_string = json_encode($data);
echo "The Json Data : ".$data_string;
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_POSTFIELDS, $data_string);
$result = curl_exec($ch);
curl_close ($ch);
echo "<p>&nbsp;</p>";
echo "The Result : ".$result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment