Slack post a message by PHP curl

Step by step process to post a message to using PHP curl:

    1. Click on Team43.  In the pop up box, choose Configure Integration.  This will take you to slack’s integration web page.
    2. Go to the bottom of the page.  Click on Incoming Webhooks.
    3. Choose a channel to add the webhook.  This will generate a webhook endpoint URL.  This will be used to set up curl.
    4. Here’s my curl code.  It is based off https://gist.github.com/alexstone/9319715:
<?php 
$message = "hello world from curl"; 
$room = "random"; 
$icon = ":smile:"; 
$data = "payload=" . json_encode(array(         
        "channel"       =>  "#{$room}",
        "text"          =>  $message,
        "icon_emoji"    =>  $icon
    ));
$url = //your webhook endpoint;
        

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
echo var_dump($result);
if($result === false)
{
    echo 'Curl error: ' . curl_error($ch);
}

curl_close($ch);