Skip to content

Instantly share code, notes, and snippets.

@szabacsik
Created January 29, 2018 12:07
Show Gist options
  • Save szabacsik/86a1c37bf699a5023bdbe047cce00f7e to your computer and use it in GitHub Desktop.
Save szabacsik/86a1c37bf699a5023bdbe047cce00f7e to your computer and use it in GitHub Desktop.
slack php function
<?php
define ( 'SLACK_WEBHOOK', 'https://hooks.slack.com/services/' );
function slack ( $message, $username, $channel )
{
switch ( $channel )
{
case 'delivery-form':
$token = '...';
break;
}
$msg = array ( 'text' => $message, "username" => "..." );
$c = curl_init ( SLACK_WEBHOOK . $token );
curl_setopt ( $c, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $c, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt ( $c, CURLOPT_POST, true );
curl_setopt ( $c, CURLOPT_POSTFIELDS, array ( 'payload' => json_encode ( $msg ) ) );
curl_exec ( $c );
curl_close ( $c );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment