使用PHP表单松弛传入的Webhook

使用PHP表单松弛传入的Webhook,php,html,json,slack-api,Php,Html,Json,Slack Api,我正在尝试创建一个PHP脚本,自动将Web表单中的文本推送到Slack频道 HTML: <form action="http://main.xfiddle.com/<?php echo pf_file('g7f-ds0'); ?>" method="post" id="myform" name="myform"> <textarea name="text" id="" rows="3" cols="30"> </textarea> <b

我正在尝试创建一个PHP脚本,自动将Web表单中的
文本推送到Slack频道

HTML:

<form action="http://main.xfiddle.com/<?php echo pf_file('g7f-ds0'); ?>" method="post" id="myform" name="myform">   
<textarea name="text" id="" rows="3" cols="30">
</textarea> <br /><br />
<button id="mysubmit" type="submit" name="submit">Submit</button><br /><br /></form>
然后将$payload更改为

'text' => $textdata

这里有两个可能的问题

  • 文章中的PHP格式不正确

    用PHP替换测试文本
    'text'=>“使用PHP测试文本”

  • 您的卷发设置不正确。请参阅以下帖子,以解决可能出现的问题-


  • 一个简单的示例,演示如何将slack传入webhook与
    curl

    <?php
    define('SLACK_WEBHOOK', 'https://hooks.slack.com/services/xxx/yyy/zzz');
    function slack($txt) {
      $msg = array('text' => $txt);
      $c = curl_init(SLACK_WEBHOOK);
      curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($c, CURLOPT_POST, true);
      curl_setopt($c, CURLOPT_POSTFIELDS, array('payload' => json_encode($msg)));
      curl_exec($c);
      curl_close($c);
    }
    ?>
    
    
    
    摘自

    'text' => $textdata
    
    <?php
    define('SLACK_WEBHOOK', 'https://hooks.slack.com/services/xxx/yyy/zzz');
    function slack($txt) {
      $msg = array('text' => $txt);
      $c = curl_init(SLACK_WEBHOOK);
      curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($c, CURLOPT_POST, true);
      curl_setopt($c, CURLOPT_POSTFIELDS, array('payload' => json_encode($msg)));
      curl_exec($c);
      curl_close($c);
    }
    ?>