How to send firebase push notification using trigger - php

I am trying to send notification whenever the database is inserted with new value but i keep getting "error in sending request" repeatedly while trying this code,not able to find what's the problem, I have used server api key as suggested. I have used one form that takes two textboxs which will be directed to the other file above.
<?php
$host='localhost';
$username='';
$pwd="";
$db="";
$con=mysqli_connect($host,$username,$pwd,$db);
if($_SERVER['REQUEST_METHOD']=='POST'){
$full_name = $_POST['full_name'];
$contact_number = $_POST['contact_number'];
//require_once('dbConnect.php');
$sql = "INSERT INTO notification (full_name,contact_number) VALUES (
'$full_name'
'$contact_number')";
$check = "SELECT * from notification where full_name='$full_name' AND contact_number='$contact_number'";
$checkData = mysqli_query($con,$check);
if (mysqli_num_rows($checkData) > 0) {
echo "Request already posted";
}else{
if(mysqli_query($con,$sql)){
$notiTitle = "notification request";
$notiMessage ="by".$full_name;
sendNotification($notiTitle, $notiMessage);
echo "sucessfully added";
}else{
echo "error in sending request";
}
}
}else{
echo 'error';
}
function sendNotification($title, $msg) {
$titlee = $title;
$message = $msg;
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "AIz#################################";
$sql = "SELECT app_id FROM user_app_id";
$result = mysqli_query($con,$sql);
// fetch all key of devices
$finalKey=array();
while($row= mysqli_fetch_array($result)){
$finalKey[]=$row['app_id'];
}
$headers = array(
'Authorization:key=' .$server_key,
'Content-Type : application/json');
$fields = array('registration_ids'=>$finalKey, 'notification'=>array('title'=>$title, 'body'=>$message));
$payload = json_encode($fields);
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$result = curl_exec($curl_session);
curl_close($curl_session);
echo $result;
mysqli_close($con);
}
<html>
<body>
<form action="init.php" method="post">
Full Name: <input type="text" name="full_name"><br>
Contact No: <input type="text" name="contact_number"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
?>
Can anyone help me on this?

Not sure if it was a typo in your code, but you need to adjust the PHP code - you've wrapped the HTML within the <?php ?> segment.
Try exiting the PHP segment before the HTML starts like below;
?>
<html>
<body>
<form action="init.php" method="post">
Full Name: <input type="text" name="full_name"><br>
Contact No: <input type="text" name="contact_number"><br>
<input type="submit" value="submit">
</form>
</body>
</html>

Related

I want to convert a post method form to curl command

I'm making an auto SMS system. But SMS provider gave me post method form but I want it to modify with curl command by my own.
they provided me
<head>
<title>SMS</title>
</head>
<body>
<form name="sms" method="post" >
<input type="text" placeholder="send to number" name="to" /><br />
<input type="textarea" placeholder="sms" name="msg" /><br />
<input type="submit" value=" OK " />
</form>
<?php
$apikey='$2y$10$t..Yr.YDG0kXYiuLwQ78OecDgz6/qh.1xSWx77mXjczkk3AEKvTZe';
if (isset($_POST["msg"]) ) {
$sendto = $_POST["to"];
$fullNumber = '880' . substr(preg_replace('/\D/', '', $sendto), -10);
$msg = urlencode($_POST["msg"]);
// $masking='CITY PORTER';
// $masking=urlencode($masking);
// masking $url='http://example.com/smsapi/masking?api_key='.$apikey.'&smsType=text&maskingID='.$masking.'&mobileNo='.$fullNumber.'&smsContent='.$msg.'';
$url='http://example.com/smsapi/non-masking?api_key='.$apikey.'&smsType=text&mobileNo='.$fullNumber.'&smsContent='.$msg.'';
if ( !empty($_POST["to"]) && !empty($_POST["msg"])) {
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL =>$url,
CURLOPT_USERAGENT =>'My Browser'
));
$resp = curl_exec($curl);
echo $resp;
curl_close($curl);
}
else
{ echo "Field is empty";}
}
?>
</body>
I converted it to curl command but this is not still working. I just want to input multiple value without is set() 1 value.
$api_key = "$2y$10$mtW.yfKj18i2mTPe/0iCEuKdCfCGh9zOYYEU9AmnMrJyBb.h7fVcG";
$number = $row[mailing_no];
$message = "Dear Guardian, ". $row[name] . " has swiped his card right now";
$type= "text";
$params = array('api_key'=>$api_key, 'smsType'=>$type, 'mobileNo'=>$number, 'smsContent'=>$message);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/smsapi/non-masking?".http_build_query($params, "", "&"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close ($ch);
Try this i hope your problem will be solve
<div id="send_reply"></div>
<form name="sms" method="post" >
<input type="text" placeholder="send to number" name="to" id="phone" /><br />
<input type="textarea" placeholder="sms" name="msg" id="mess" /><br />
<input type="submit" value=" OK " id="send_btn" />
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#send_btn").click(function(){
var txt1=$("#phone").val();
var txt2=$("#mess").val();
$.ajax({
url : 'check.php',
method : 'GET',
data : {txt1:txt1,txt2:txt2},
success:function(dda){
$("#send_reply").html(dda);
}
});
});
});
</script>
I think we were missing double quotes for $row keys, try this:
$api_key = "$2y$10$mtW.yfKj18i2mTPe/0iCEuKdCfCGh9zOYYEU9AmnMrJyBb.h7fVcG";
$number = $row["mailing_no"];
$message = "Dear Guardian, ". $row["name"] . " has swiped his card right now";
$type= "text";
$params = array('api_key'=>$api_key, 'smsType'=>$type, 'mobileNo'=>$number, 'smsContent'=>$message);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/smsapi/non-masking?".http_build_query($params, "", "&"));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type:application/json", "Accept:application/json"));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($ch);
curl_close ($ch);

405 method not allowed json data not post

I am making simple form of posting details in php but got stuck while posting data from form to API but it is showing 405 method not allowed error. Please check my code below and let me know what is the issue in it. Might be I am doing some silly mistake, sorry if that is the case.
<form method="POST" action="#" name="checkout">
First Name <input type="text" name="firstName"/><br/>
Last name <input type="text" name="lastName"/><br/>
Email <input type="text" name="phone"/><br/>
Phone <input type="text" name="gender"/><br/>
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$name = $_POST['firstName'];
$lastname = $_POST['lastName'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$url11 = "https://api.rezdy.com/v1/categories/124095/products?apiKey=bb42962c78b34e02b879cc5463cb4648";
$data['customer'] = array(
'firstName'=>$name,
'lastName'=>$lastname,
'email'=>$phone,
'phone'=>$gender
);
echo "<pre>";
$json = json_encode($data);
echo $json;
echo "<br/>";
function senddatat($url,$post)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','charset=UTF-8 '));
$result = curl_exec($ch);
/*echo "<pre>";
var_dump( curl_getinfo($ch) ) . '<br/>';
echo curl_errno($ch) . '<br/>';
echo curl_error($ch) . '<br/>';
curl_close($ch);*/
return $result;
}
echo " ".senddatat($url11,$json);
}
?>
Check The Silly Mistakes First: This Is Your Fields: firstName,lastName,phone,gender
<input type="text" name="firstName"/><br/>
<input type="text" name="lastName"/><br/>
<input type="text" name="phone"/><br/>
<input type="text" name="gender"/><br/>
and What you get in the post request: firstName,lastName,email,phone i dont know how you get the email in post request ????
$name = $_POST['firstName'];
$lastname = $_POST['lastName'];
$email = $_POST['email'];
$phone = $_POST['phone'];
Updated:
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" name="checkout">
First Name <input type="text" name="firstName"/><br/>
Last name <input type="text" name="lastName"/><br/>
phone <input type="text" name="phone"/><br/>
gender <input type="text" name="gender"/><br/>
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']) && !empty($_POST['firstName']) && !empty($_POST['lastName']) && !empty($_POST['phone']) && !empty($_POST['gender']) ){
$name = $_POST['firstName'];
$lastname = $_POST['lastName'];
$phone= $_POST['phone'];
$gender= $_POST['gender'];
$url11 = "https://api.rezdy.com/v1/categories/124095/products?apiKey=bb42962c78b34e02b879cc5463cb4648";
$data['customer'] = array('firstName'=>$name,'lastName'=>$lastname,'email'=>$phone,'phone'=>$gender);
echo "<pre>";
$json = json_encode($data);
echo $json;
echo "<br/>";
function senddatat($url,$post)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','charset=UTF-8 '));
$result = curl_exec($ch);
/*echo "<pre>";
var_dump( curl_getinfo($ch) ) . '<br/>';
echo curl_errno($ch) . '<br/>';
echo curl_error($ch) . '<br/>';
curl_close($ch);*/
return $result;
}
echo " ".senddatat($url11,$json);
}
?>
There is some errors in your form and post request. Also when you are calling ssl verified api. You need to pass ssl certificate with it. Or temporary you can disable it by CURLOPT_SSL_VERIFYPEER to FALSE
Try this code:
<form method="POST" action="#" name="checkout">
First Name <input type="text" name="firstName"/><br/>
Last name <input type="text" name="lastName"/><br/>
Email <input type="text" name="email"/><br/>
Phone <input type="text" name="phone"/><br/>
<input type="submit" name="submit" value="submit"/>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$name = $_POST['firstName'];
$lastname = $_POST['lastName'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$url11 = "https://api.rezdy.com/v1/categories/124095/products?apiKey=bb42962c78b34e02b879cc5463cb4648";
$data['customer'] = array(
'firstName'=>$name,
'lastName'=>$lastname,
'email'=>$email,
'phone'=>$phone
);
echo "<pre>";
$json = json_encode($data);
echo $json;
echo "<br/>";
function senddatat($url,$post)
{
$ch = curl_init();
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"POST");
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_POST,true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','charset=UTF-8 '));
$result = curl_exec($ch);
/* echo "<pre>";
var_dump( curl_getinfo($ch) ) . '<br/>';
echo curl_errno($ch) . '<br/>';
echo curl_error($ch) . '<br/>';*/
curl_close($ch);
return $result;
}
echo " ".senddatat($url11,$json);
}
EDIT
Note : Error clearly tells that Method Not Allowed it means POST method is not allowed for https://api.rezdy.com/v1/categories/124095/products api you need to refer api doc

I am trying to make a custom User creation with ZenDesk(CRM)

This site helped me out a lot last time I had an issue. I was wondering why this php code was not working. Any help would be appreciated. I am trying to make a custom user creation request with ZenDesk.
I got the request to work, but when I edited the code to fit it into the actual Instance of my CRM it does not even try to make a PHP request. I verified this should be possible if the code is correct. I Just can not figure out why it is not correct.
<?php
include("config.php");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://url/api/v2/users.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"user\": {\"name\": \"$name\",
\"email\": \"$email\", \"phone\": \"$phone"}}");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, "email" . ":" . "password");
$phone = phone;
$email = email;
$name = name;
$headers = array();
$headers[] = "Content-Type: application/json";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
if ( !isset ($_POST['Name']) ||
!isset ($_POST['Name'] ||
!isset ($_POST['phone']
)
{
}
curl_close ($ch);
?>
<!DOCTYPE html>
<html>
<body>
<form
action="://url/agent/users/{{user.id}}/requested_tickets">
First name:<br>
<input type="text" name="name" value="name">
<br>
Last name:<br>
<input type="text" name="email" value="email">
<br><br>
<input type="text" name="phone" value="+15555555555">
<br><br>
<input type="submit" value="Submit">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a
page
called "/action_page.php".</p>
</body>
</html>

MailChimp group options select in php

I tried to find the answer for the last 5 hours but I finally caved in and am reaching out for help.
Basically, this code worked great until I needed to select a group option. I'm not sure if I'm creating my interests array properly, I may have to use 'merge_vars' but really would like some guidance before I spend another 5 hours blindly walking into walls.
Note for my group name I've been using the entire string "group[3117]"
Action.php
<?php
session_start();
if(isset($_POST['submit'])){
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$interest = $_POST['group[3117]'];
if(!empty($email) && !filter_var($email, FILTER_VALIDATE_EMAIL) === false){
// MailChimp API credentials
$apiKey = '+ insert api key here +';
$listID = 'insert list id';
$interest = 'insert group name'; // YOUR INTEREST/GROUP ID
// MailChimp API URL
$memberID = md5(strtolower($email));
$dataCenter = substr($apiKey,strpos($apiKey,'-')+1);
$url = 'https://' . $dataCenter . '.api.mailchimp.com/3.0/lists/' . $listID . '/members/' . $memberID;
// member information
$json = json_encode([
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => [
'FNAME' => $fname,
'LNAME' => $lname
],
'interests' => array(
$interest => true
),
]);
// send a HTTP POST request with curl
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_USERPWD, 'user:' . $apiKey);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// store the status message based on response code
if ($httpCode == 200) {
$_SESSION['msg'] = '<p style="color: #34A853">You have successfully subscribed to CodexWorld.</p>';
} else {
switch ($httpCode) {
case 214:
$msg = 'You are already subscribed.';
break;
default:
$msg = 'Some problem occurred, please try again.';
break;
}
$_SESSION['msg'] = '<p style="color: #EA4335">'.$msg.'</p>';
}
}else{
$_SESSION['msg'] = '<p style="color: #EA4335">Please enter valid email address.</p>';
}
}
// redirect to homepage
header('location:index.php');
Index.php
<?php session_start(); // place it on the top of the script ?>
<?php
$statusMsg = !empty($_SESSION['msg'])?$_SESSION['msg']:'';
unset($_SESSION['msg']);
echo $statusMsg;
?>
<form method="post" action="action.php">
<p><label>First Name: </label><input type="text" name="fname" /></p>
<p><label>Last Name: </label><input type="text" name="lname" /></p>
<p><label>Email: </label><input type="text" name="email" /></p>
<p><select name="group[3117]" class="REQ_CSS" id="mce-group[3117]">
<option value=""></option>
<option value="1">Los Angeles</option>
<option value="2">Seattle</option>
<option value="4">Portland</option> </p>
<p><input type="submit" name="submit" value="SUBSCRIBE"/></p>
</form>
Here's the solution, there's a lot of manual data entry but it works, if someone has an easier method please let me know.
Enter the MailChimp API playground. Select your list / subresources / interest-categories / interest name / subresources / interests / response . scroll down and there will be a unique "id" for interest. (ignore category id)
Here is the code, credit goes Mukesh Chapegan and CodexWorld
Name this page Action.php
<?php
$email = $_POST['email'];
$memberHash = md5($email);
$first_name = $_POST['fname'];
$last_name = $_POST['lname'];
$interest = $_POST['location'];
$api_key = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'; // YOUR API KEY
$server = 'us14.'; //last part of ur api key
$list_id = 'XXXXXXX'; // YOUR LIST ID
$auth = base64_encode( 'user:'.$api_key );
$data = array(
'apikey' => $api_key,
'email_address' => $email,
'status' => 'subscribed',
'merge_fields' => array(
'FNAME' => $first_name,
'LNAME' => $last_name
),
'interests' => array(
$interest => true
),
);
$json_data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$server.'api.mailchimp.com/3.0/lists/'.$list_id.'/members/'.$memberHash);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
'Authorization: Basic '.$auth));
curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-MCAPI/2.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$result = curl_exec($ch);
$result_obj = json_decode($result);
echo $result_obj->status;
echo '<br>';
echo '<pre>'; print_r($result_obj); echo '</pre>';
?>
Here is the HTML form. name this index.php
Note I named the select element to location and the option values to the interest id I obtained through the API playground.
<?php session_start(); // place it on the top of the script ?>
<?php
$statusMsg = !empty($_SESSION['msg'])?$_SESSION['msg']:'';
unset($_SESSION['msg']);
echo $statusMsg;
?>
<form method="post" action="action.php">
<p><label>First Name: </label><input type="text" name="fname" /></p>
<p><label>Last Name: </label><input type="text" name="lname" /></p>
<p><label>Email: </label><input type="text" name="email" /></p>
<p> <select name="location" class="REQ_CSS" id="mce-group[3117]">
<option value=""></option>
<option value="f3eb68268d">Los Angeles</option>
<option value="3204c60199">Seattle</option>
<option value="3c5b8d638a">Portland</option> </p>
</select>
<p><input type="submit" name="submit" value="SUBSCRIBE"/></p>
</form>
If this answer helps please upvote so it's easier to find. I looked for this solution for a very very long time and found a lot of questions but few answers.

Send Firebase Cloud Messaging to mobile phone devices

I just developed a sample of firebase with apps server in my live webserver.
I tried it on my localhost pc (offline) and firebase notification are sent on virtual devices android.
But when i try to install apk file into my phone devices and transfer PHP file into my live server (i.e www.aaa.com).
Firebase notification does not work at all. it doesn't send into my phone devices.
Am i missing something on the code ? . The code as below. Thanks.
<?php
require "connect.php";
global $con;
if(isset($_POST['Submit'])){
$message = $_POST['message'];
$title = $_POST['title'];
$path_to_fcm = 'https://fcm.googleapis.com/fcm/send';
$server_key = "SERVER KEY HERE";
echo "Data sent ! <br/>";
$sql = "SELECT fcm_token FROM fcm_info";
$result = mysqli_query($con, $sql);
$row = mysqli_fetch_row($result);
$key = $row[0];
$headers = array('Authorization:key=' .$server_key, 'Content-Type:application/json');
$fields = array('to' => $key, 'notification' => array('title' => $title, 'body'=> $message));
$payload = json_encode($fields);
$curl_session = curl_init();
curl_setopt($curl_session, CURLOPT_URL, $path_to_fcm);
curl_setopt($curl_session, CURLOPT_POST, true);
curl_setopt($curl_session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl_session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_session, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_session, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl_session, CURLOPT_POSTFIELDS, $payload);
$result = curl_exec($curl_session);
curl_close($curl_session);
mysqli_close($con);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Send Notification</title>
</head>
<body>
<form action='send_notification.php' method="POST">
<table>
<tr>
<td>Title : </td>
<td><input type="text" name="title" required="required" /></td>
</tr>
<tr>
<td>Message : </td>
<td><input type="text" name="message" required="required" /></td>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Send notification"></td>
</tr>
</table>
</form>
</body>
</html>
<?php
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header=array('Content-Type: application/json',
"Authorization: key=YOUR KEY");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{ \"notification\": { \"body\": \"Weather Forecast\",
\"title\": \"YOur title\",
\"to\" : \"YOUR DEVICE REG TOKEN\"}"
curl_exec($ch);
curl_close($ch);
?>
go to your firebase console the project settings> select second tab 'cloud messaging' there would be your server key which your will need in your php file ;)

Categories