Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jdc-cunningham/bfef0e3824c2bc132ebc2032e0c1437e to your computer and use it in GitHub Desktop.

Select an option

Save jdc-cunningham/bfef0e3824c2bc132ebc2032e0c1437e to your computer and use it in GitHub Desktop.
PHP Slack Webhook Function Using CURL
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
@jdc-cunningham

Copy link
Copy Markdown
Author

Note that this requires CURL to work on your machine/server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment