Document Example Transaction

HTML (index.php)


  <body>

  =========================================================
  =   Send transaction to email 
  =========================================================
  <form class="" action="control.class.php?method=post" method="post">
    <input type="text" name="from_name" value="">
    <input type="text" name="from_email" value="">
    <input type="text" name="to" value="">
    <input type="text" name="subject" value="">
    <textarea name="body" rows="8" cols="80"></textarea>
    <button type="submit">send</button>
  </form>

  </body>

                        

PHP (control.class.php)


  <?php

  if($_POST){
    $data['from_name'] = $_POST['from_name'];
    $data['from_email'] = $_POST['from_email'];
    $data['to'] = $_POST['to'];
    $data['subject'] = $_POST['subject'];
    $data['body'] = $_POST['body'];
  }

  $url = 'https://app-a.nipamail.com/api/v1/transactional';
  $key = 'ffa67286202c04c8af6aeb512579ead5d5896054aabb071';


  if($_GET['method']){
    $rs = NULL;
    switch($_GET['method']){
      case 'post': $rs = _post($data, $url, $key); break;
      case 'get': $rs = _get($url, $key); break;
    }
    print_r($rs);
  }


  if($_GET['func']){
    switch($_GET['func']){
      case 'getTransactional': _getTransactional(); break;
    }

    print_r($rs);

    ====================================================
    = sent request method get : GET REPORT 
    ====================================================
    $rs = _get($url, $key);
    if($rs->code == 200){
      print_r($rs);
    }
    else echo '<span style="color:red">Error! :' . rs->message . '</span>';

  }


  ====================================================
  = sent request method post : to $url 
  ====================================================
  function _post($data=array(), $url='', $key=''){
    $data_string = json_encode($data);
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json','HTTP_ACCEPT_LANGUAGE','session_key:'.$key,'Content-Length: '.strlen($data_string)));
    $output = curl_exec($ch);
    curl_close($ch);
    $content = json_decode($output);
    return $content;
  }


  ====================================================
  = sent request method get : to $url 
  ====================================================
  function _get($url='', $key=''){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_TIMEOUT, '3');
    curl_setopt($ch, CURLOPT_HTTPHEADER,array( 'Content-Type: application/json','HTTP_ACCEPT_LANGUAGE','session_key:'.$key));
    $output = curl_exec($ch);
    curl_close($ch);
    $content = json_decode($output);
    return $content;
  }