php-gcm project for sending sms to any number through google cloud messaging


This is an opensource project by me and final release is version 1.0.1 till now.
First we have to create index.php for the options that will give the senders number and text box what to send to the sender and then at last the resgistration id from your mobile phone(It will be needed to use your mobile phone as messaging server.It will come from GCM app).


author:Syed Ahmed Zaki
app_idea:Mohammad Amir Hamza

<title>SMS Gateway</title>

<form action="gcmtest.php" method="GET">
  Mobile Nummer</label>
<input type="text" name="numb">
<textarea name="mess"></textarea>
<textarea name="id">registration id from your device</textarea>
<input type="submit" name="btn" value="SUBMIT">


Now we have to create gcmtest.php it is the core part of our project.Here all the settings available that you can customize easily according to your needs.



author:Syed Ahmed Zaki
app_idea:Mohammad Amir Hamza

// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'Your API server key is here' );
$registrationIds = array( $_GET['id'] ); //it is getting registration id from the index page.

// prep the bundle.You can define the desired values from gcm library.I needed message and number only so it has defined here.
$msg = array
	'message' 	=> $_GET['mess'],
	'number'	=> $_GET['numb'],
//It is json passing
$fields = array
	'registration_ids' 	=> $registrationIds,
	'data'			=> $msg,
$headers = array
	'Authorization: key=' . API_ACCESS_KEY,
	'Content-Type: application/json'
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, '' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;

Now when we run the script from our php backend server then it will show you the page where you will input sender number and message and click submit it will pass through your phone to google cloud messaging server and receiver will recieve a sms from your number.

You can download this whole project from my mirror server:

For testing this app you can go to:
github address for source code:

I took help from the opensource project to learn how they did the gcm passing: (In PHP) (Android SMS gateway call in Ruby)

If you liked the tutorial or face any problem don’t forget to comment in the comment section.Thanx for reading 🙂


It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

Your email address will not be published. Required fields are marked *