Skip to content

Instantly share code, notes, and snippets.

@Depicus
Created December 26, 2014 13:13
Show Gist options
  • Save Depicus/d61d7e149364467893c3 to your computer and use it in GitHub Desktop.
Save Depicus/d61d7e149364467893c3 to your computer and use it in GitHub Desktop.
PHP function to send a message to Slack
function sendSlackMessage($text, $username = "PHP Error Bot", $channel = "#general")
{
$url = "https://hooks.slack.com/services/your-token-here";
$payload = array();
$payload["username"] = $username; // you can customise this
$payload["channel"] = $channel;
$payload["text"] = $text;
// set up & post curl
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'payload='.json_encode($payload));
$result = curl_exec($ch);
if($result === FALSE) {
//send email or do something else here
}
curl_close($ch);
}
sendSlackMessage("Well thank you Brian", "Paypal Payment Accepted");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment