Skip to content

Instantly share code, notes, and snippets.

@mtruitt
Created May 7, 2018 20:59
Show Gist options
  • Save mtruitt/a57216b62eaced4365147d8ef97a07e7 to your computer and use it in GitHub Desktop.
Save mtruitt/a57216b62eaced4365147d8ef97a07e7 to your computer and use it in GitHub Desktop.
Send via Slack Webhook
<?php
$message = array( 'text' => 'This is a test message via slack and curl' );
$data_message = json_encode( $message );
$ch = curl_init( 'slack webhook goes here' );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_message);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_message))
);
$result = curl_exec($ch);
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment