Created
December 26, 2014 13:13
-
-
Save Depicus/d61d7e149364467893c3 to your computer and use it in GitHub Desktop.
PHP function to send a message to Slack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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