Slack Incoming Webhook with Php Curl

Asterisk and Freeswitch solutions (форма рабочая, напишите нам :)


php

<?php
$recaptcha = $_POST['g-recaptcha-response'];
if(!empty($recaptcha)) {
    $recaptcha = $_REQUEST['g-recaptcha-response'];
    $secret = 'RECAPTCHA_SECRET';
    $url = "https://www.google.com/recaptcha/api/siteverify?secret=".$secret ."&response=".$recaptcha."&remoteip=".$_SERVER['REMOTE_ADDR'];
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_TIMEOUT, 10);
    curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16");
    $curlData = curl_exec($curl);
    curl_close($curl);
    $curlData = json_decode($curlData, true);
    if($curlData['success']) {
       $txt = $_POST['text'];
       $tel = $_POST['tel'];
       $mail = $_POST['mail'];
  define('SLACK_WEBHOOK', 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX');
  $msg = array('text' => $mail."\n".$tel."\n".$_SERVER['REMOTE_ADDR']."\n".$txt);
    $c = curl_init(SLACK_WEBHOOK);
  curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
  curl_setopt($c, CURLOPT_POST, true);
  curl_setopt($c, CURLOPT_POSTFIELDS, array('payload' => json_encode($msg)));
  curl_exec($c);
  curl_close($c);
    }
} else {
   echo "Error!";
}
?>

html

<form id="Message" action="#" method="POST">
  <div class="form-group">
  <label for="Email">Email*</label>
    <br/>
    <input type="email"  id="mail" name="mail" value="" size="36" required>
  </div>
  <br/><br/>
  <div class="form-group">
    <label for="Phone">Phone</label>
    <br/>
    <input type="tel"  id="tel" name="tel" size="36" value=""/>
  </div>
  <br/><br/>
   <div class="form-group">
    <label for="text">Message</label>
    <br/>
    <textarea rows="5" cols="36" id="text" name="text" value="">
    </textarea>
  </div>
  <br/><br/>
    <div class="g-recaptcha"  data-sitekey="RECAPTCHA_KEY"></div>
    <br/><br/>
    <button
        type="submit" class="btn btn-primary">Send
    </button>
    <br/>
   </form>
<br/><br/>
  <script src='https://www.google.com/recaptcha/api.js?hl=en'></script>

Slack API: Incoming Webhooks

2018/07/05 · Zvezdo4kin · 0 комментариев (-я)

Предыдущие записи >>

Только авторизованные участники могут оставлять комментарии.
  • blog.txt
  • Последние изменения: 2018/07/04