LoginSignup
4
5

More than 5 years have passed since last update.

BlaynMailのAPIを呼び出して、メール配信履歴をテーブル表示しました。PGは、10行!

Last updated at Posted at 2015-09-26

顧客管理システムのメールアドレスにメールを一括送信するプログラムを作成しています。

顧客管理のデータは、Office365のSharePointで管理して、メール送信はBlaynMailのAPIを利用して作成するプログラムコードを極力減らしたい。

そのために画面のレイアウトは、AdminLTEを使ってデータを送信するだけにしました。環境設定のコードを除けば、30行程度のプログラムコードで書くことができました。

image

▼動作確認用のサンプル画面
http://otoku55.sakura.ne.jp/phpStudy/bf_history.php

bf_histiry.php


Smartyの環境設定とBlaynMailのログイン認証

$url = "http://api.bme.jp/rest/1.0/message/history/search?access_token={$xml->access_token}";

$request->reset($url);

$request->setMethod(HTTP_REQUEST_METHOD_GET);

$result = $request->sendRequest();
if (!PEAR::isError($result)) {
  //echo $request->getResponseBody();
  $sxml=  simpleXML_load_string($request->getResponseBody());  

  $w_Draft = array();
  $w_Data = array();
  $j = 0;
  foreach ($sxml->message as $message ){
      $w_Data[0] = $message->date;
      $w_Data[1] = $message->subject;
      $w_Data[2] = $message->group;
      $w_Data[3] = $message->total;
      $w_Data[4] = $message->success;
      $w_Data[5] = $message->failure;
      $w_Data[6] = $message->status;
      $w_Draft[$j] = array($w_Data[0], $w_Data[1], $w_Data[2], $w_Data[3], $w_Data[4], $w_Data[5], $w_Data[6]);

      $j++;
    }

    $smarty->assign('s_Draft',$w_Draft);

    //下書き
    $smarty->display( 'bf_history.tpl' );
}


変数 "s_Draft" にデータをセットして、テンプレートを呼び出します。
メインコンテンツのコードは、"s_Draft"の変数値を受け取るだけです。

bf_history.tpl

      <!-- Content Wrapper. Contains page content -->
      <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
          <h1>
            配信履歴の確認
            <small>preview of simple tables</small>
          </h1>
          <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> ホーム</a></li>
            <li class="active">配信履歴の確認</li>
          </ol>
        </section>

        <!-- Main content -->
        <section class="content">

          <div class="row">
            <div class="col-xs-12">
              <div class="box">
                <div class="box-header">
                  <h3 class="box-title">配信完了メール</h3>
                  <div class="box-tools">
                    <div class="input-group" style="width: 150px;">
                      <input type="text" name="table_search" class="form-control input-sm pull-right" placeholder="Search">
                      <div class="input-group-btn">
                        <button class="btn btn-sm btn-default"><i class="fa fa-search"></i></button>
                      </div>
                    </div>
                  </div>
                </div><!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                  <table class="table table-hover">
                    <tr>
                      <th>登録日時</th>
                      <th>件名</th>
                      <th>宛先</th>
                      <th>配信</th>
                      <th>成功</th>
                      <th>失敗</th>
                      <th>配信完了</th>
                    </tr>
                    {foreach from=$s_Draft item=drfset}
                    <tr>
                      <td>{$drfset[0]}</td>
                      <td>{$drfset[1]}</td>
                      <td>{$drfset[2]}</td>
                      <td>{$drfset[3]}</td>
                      <td>{$drfset[4]}</td>
                      <td>{$drfset[5]}</td>
                      <td>{$drfset[6]}</td>
                    </tr>
                    {/foreach}
                  </table>
                </div><!-- /.box-body -->
              </div><!-- /.box -->
            </div>
          </div>
        </section><!-- /.content -->
      </div><!-- /.content-wrapper -->

毎週土曜日に開催しているphp勉強会(主催:阿部情報技術研究所 http://www.alit.jp/ )で解らないことを質問して、問題を解決しています。

image

※初回投稿時は、30行ほどのコードだったのですが、
アドバイスを頂いて、下記のようにコードを修正しましたら、スッキリと10行になりました。

4
5
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
5