Created
October 4, 2017 12:53
-
-
Save jdc-cunningham/bfef0e3824c2bc132ebc2032e0c1437e to your computer and use it in GitHub Desktop.
PHP Slack Webhook Function Using CURL
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 sendWebhook($message) { | |
| $webhook_url = ""; | |
| // slack webhook test | |
| $data = "payload=" . json_encode(array( | |
| "text" => $message | |
| )); | |
| $ch = curl_init($webhook_url); | |
| curl_setopt_array($ch, array( | |
| CURLOPT_POST => 1, | |
| CURLOPT_POSTFIELDS => $data | |
| )); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
| $result = curl_exec($ch); | |
| curl_close($ch); | |
| } | |
| sendWebhook($message_str); // call function with string message |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this requires CURL to work on your machine/server