Skip to content

Instantly share code, notes, and snippets.

@shyazusa
Last active September 12, 2016 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shyazusa/518e53fbd2dcbd1ec2195e0fc5c79253 to your computer and use it in GitHub Desktop.
Save shyazusa/518e53fbd2dcbd1ec2195e0fc5c79253 to your computer and use it in GitHub Desktop.
PHPからSlackへチャットを送る
<?php
// slack
$mes = print_r('', true); // ここにメッセージなり配列変数ブチ込んで
$headers = array();
$url = 'https://hooks.slack.com/services/hoge/fuga/piyo/';
$payload = array(
'text' => $mes,
// 'text' => '<@shy_azusa>: '.$mes, // @したい場合はこっち
'channel' => '#server_log', // 好きなチャンネルへどうぞ
);
$params = array('payload' => json_encode($payload));
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_exec($ch);
curl_error($ch);
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment