background-hooknotifierbackground-hooknotifier
Last update: Feb 25, 20236 minutes read

Receive push notifications from PHP

illuday

Emmanuel Russeil

February 25, 2023

Interact with your phone from your PHP server. Set up and send notifications quickly using Hook.Notifier.

Introduction

About PHP

Web application design server language, although in decline, PHP remains a monster in the domain with many applications and websites built with this technology.

Check PHP official website

About Hook.Notifier

Hook.Notifier is a notification collector, it allows you to send, store and organize useful notifications on your phone from various services.

Check Hook.Notifier official website

Our first notification from PHP

hook notifier notification

Objective

The goal is simple here, to receive a test notification from a PHP file.

Curl to our rescue

To communicate with Hook.Notifier, we will need cURL, if it is not already the case, you will need to install the library on your PHP environment, no additional dependencies are required. To know if cURL is installed, look at your phpinfo(); or try to run the script below, if the cURL functions are not found it means that your environment is not correctly installed.

1. A small PHP script

We have created a simple PHP script that includes all the parameters that Hook.Notifier makes available to us. For more information, we refer you to our article Get Started.

get started with hook.notifier header

Get started with Hook.Notifier

This article aims to introduce you to Hook.Notifier, including its benefits, recommended introductory articles, and developer documentation.

This script can be included in any type of PHP environment, you also don't have to take any precautions regarding your credentials since your script should not be accessible to your site's users. Include it, of course, where you need to trigger a notification.

[[PHP]]// Required
    $identifier = %_YOUR_IDENTIFIER_%;
    $key = "%_YOUR_KEY_%";
    
    $object = urlencode("My notification from PHP");
    $body = urlencode("Hooray, my notification from PHP has been sent!");

    // Optional
    $tags = "php,test";
    $color = urlencode("#7C86B4");
    $image = "https://cdn.hooknotifier.com/receive_notification_from_php_header_a7ede2135c.png";
    $redirectUrl = "https://hooknotifier.com";
    $sound = true;
    $sendToTeam = false;
    $preventData = false;

    $innerData = array(
	'author' => '...',
    	'message' => '...',
        'receiver' => '...',
        // anything you want...
    );

    // Do not touch

    $parameters = "object=$object&body=$body&tags=$tags&color=$color&image=$image&redirectUrl=$redirectUrl&sendToTeam=$sendToTeam&sound=$sound&preventData=$preventData";

    $ch = curl_init("https://moon.hooknotifier.com/$identifier/$key?$parameters");

    $payload = json_encode($innerData);
	
    curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
	
    curl_exec($ch);
    curl_close($ch);

This script simply executes a cURL call to our Hook.Notifier server sending the parameters of your notification. Remember to change your %_YOUR_IDENTIFIER_% and %_YOUR_KEY_% credentials and to vary the different parameters of your notification to suit your needs.

2. Triggering and sending

All you have to do is to trigger the sending of your notification by executing your PHP script. You should receive your notification in the second!

Our notification from PHP has arrived
Our notification from PHP has arrived

Conclusion

You should now be able to send notifications from your PHP environment, whether we are talking about Wordpress, Symfony, Laravel or any type of PHP technology, everything should work the same.

Send notifications about your form submissions, inject data in the subject or body of your notification, retrieve statistics... The possibilities are endless with Hook.Notifier. Be creative!


If you like this article, feel free to connect with us on Twitter.

If you have any questions or special requests, such as needing clarification on the terms discussed in this article, more information on a specific part, or additional articles and tutorials, please feel free to provide feedback through the widget below.

illuday

Emmanuel Russeil

February 25, 2023

What do you think of this article?

robot need an integration

You need an integration?

Let us know what you need, we will work to bring you a solution.

Fill our form

Related

get started with hook.notifier header

Get started with Hook.Notifier

This article aims to introduce you to Hook.Notifier, including its benefits, recommended introductory articles, and developer documentation.

get notifications from wordpress header

Receive push notifications from Wordpress

This article will explore different options for sending push notifications from a Wordpress environment, ranging from fully no-code methods to custom development for more advanced users.