メール一覧取得(一斉メール配信)

サンプルプログラム PHP

            <?php
            
            /////////////////////////////
            // 接続先URLを用意
            /////////////////////////////
            // ドメイン(●の部分) https://●●●●●/■■■■■/api/index.php?ac=GetMailList
            $domain = '●●●●●';
            
            // ログインURL(■の部分) https://●●●●●/■■■■■/api/index.php?ac=GetMailList
            $login_url = '■■■■■';
            
            
            /////////////////////////////
            // POSTパラメータを用意
            /////////////////////////////
            // 接続用パスワード
            $transport_passwd = '◆◆◆◆◆';
            
            // 文字コード
            $charset = '◆';
            
            // 取得形式
            $return_format = '◆◆◆';
            
            // メール状態
            $mail_status = '◆';
            
            // メール形式
            $mail_type = '◆';
            
            // 期間指定(FROM)
            $from_date = '◆◆◆◆◆';
            
            // 期間指定(TO)
            $to_date = '◆◆◆◆◆';
            
            
            /////////////////////////////
            // POSTパラメータを用意
            /////////////////////////////
            $postDataArray = array();
            $postDataArray[] = "---attached\r\n";
            $postDataArray[] = "Content-Disposition: form-data; name=\"transport_password\"\r\n\r\n" . $transport_passwd . "\r\n";
            $postDataArray[] = "---attached\r\n";
            $postDataArray[] = "Content-Disposition: form-data; name=\"charset\"\r\n\r\n" . $charset . "\r\n";
            $postDataArray[] = "---attached\r\n";
            $postDataArray[] = "Content-Disposition: form-data; name=\"return_format\"\r\n\r\n" . $return_format . "\r\n";
            $postDataArray[] = "---attached\r\n";
            $postDataArray[] = "Content-Disposition: form-data; name=\"mail_status\"\r\n\r\n" . $mail_status . "\r\n";
            $postDataArray[] = "---attached\r\n";
            $postDataArray[] = "Content-Disposition: form-data; name=\"mail_type\"\r\n\r\n" . $mail_type . "\r\n";
            $postDataArray[] = "---attached\r\n";
            $postDataArray[] = "Content-Disposition: form-data; name=\"from_date\"\r\n\r\n" . $from_date . "\r\n";
            $postDataArray[] = "---attached\r\n";
            $postDataArray[] = "Content-Disposition: form-data; name=\"to_date\"\r\n\r\n" . $to_date . "\r\n";
            $postDataArray[] = "---attached\r\n";
            
            /////////////////////////////
            // HTTPリクエストを用意
            /////////////////////////////
            $request = "POST /" . $login_url . "/api/index.php?ac=GetMailList HTTP/1.1\r\n";
            $request .= "Host: " . $domain . "\r\n";
            
            $length = 0;
            foreach ($postDataArray as $data) {
              $length += is_array($data) ? $data[1] + strlen("\r\n") : strlen($data);
            }
            
            $headers = array(
              "Content-Type: multipart/form-data; boundary=-attached",
              "Connection: close",
              "Content-Length: " . $length
            );
            
            $request .= implode("\r\n", $headers) . "\r\n\r\n";
            
            /////////////////////////////
            // POST送信
            /////////////////////////////
            $errno = 0;
            $errstr = 0;
            $fp = fsockopen('ssl://' . $domain, 443, $errno, $errstr, 10);
            if (!$fp) {
              die("接続に失敗しました。\n");
            }
            
            fputs($fp, mb_convert_encoding($request, 'UTF-8', 'UTF-8'));
            
            foreach ($postDataArray as $data) {
              if (is_array($data)) {
                $fpCsv = fopen($data[0], 'r');
                while (!feof($fpCsv)) {
                  fputs($fp, fread($fpCsv, 8192));
                }
                fclose($fpCsv);
                fputs($fp, "\r\n");
              } else {
                fputs($fp, $data);
              }
            }
            
            
            /////////////////////////////
            // レスポンス取得
            /////////////////////////////
            $httpheader = "";
            $response = "";
            
            while (!feof($fp)) {
              $tmpResponse = fgets($fp, 4096);
              if (preg_match('/^(\r|\n)+$/x', $tmpResponse)) {
                break;
              }
              $httpheader .= $tmpResponse;
            }
            
            while (!feof($fp)) {
              $response .= fgets($fp, 4096);
            }
            
            fclose($fp);
            
            switch ($charset) {
              case 1:
                $charsetStr = 'UTF-8';
                break;
              case 2:
                $charsetStr = 'Shift-JIS';
                break;
              case 3:
                $charsetStr = 'EUC-JP';
                break;
            }
            
            echo mb_convert_encoding($response, 'UTF-8', $charsetStr) . "\n";
            ob_flush();
            ?>  
            

クルメル関連サイト情報

  • 配配メール
  • メルラボ
  • メールディーラー
  • 楽楽販売
  • Pマーク