title: How to send a gcm message in php without using cURL?
body: <p>I'm using the following code to make HTTP POST request to the gcm server. 
  The code always returns "Unauthorized Error 401". I read that it is about the headers but can't figure out whats wrong.
  Can anyone tell me what's wrong? 
  Is there any other way to send a gcm message?
   Any help would be appreciated.</p>
  
  <pre><code>$api_key = "AIzaSyBhuPSdHmq6-************_qxSJr8d0";
  
  $message = array("msg_url" =&gt; $msg_url, "msg_title" =&gt; $msg_title);
  
  $url = 'https://android.googleapis.com/gcm/send';
  
  $fields = array('registration_ids'  =&gt; $ids,'data'=&gt; array( "message" =&gt; $message ));
  
  $headers = array('Authorization: key=' . $api_key,'Content-Type: application/json');
  
  // use key 'http' even if you send the request to https://...
  $options = array(
      'http' =&gt; array(
          'header'=&gt; $headers ,
          'method'  =&gt; 'POST',
          'content' =&gt; json_encode($fields),
      ),
  );
  $context  = stream_context_create($options);
  $result = file_get_contents($url, false, $context);
  
  var_dump($result);
  </code></pre>