duanlu6268 2018-07-21 08:35
浏览 62
已采纳

一切正常时失败

I am trying to fetch email contents and put it in a mysqli table deposit. Basically its coinpayments Emails which is sent when there is a deposit to an address. As they dont have an api for deposit history,I tried to develop an email reader which would read the email and put the address,username and txid in deposits table. The email when exploded to arrays looks like this

 Array ( [0] => -----BEGIN [1] => PGP [2] => SIGNED [3] => MESSAGE-----Hash: 
 [4] => SHA256Hello [5] => an user [6] => deposit [7] => of [8] => 
 an amount [9] => LTCT [10] => has [11] => been [12] => received [13] => 
 and [14] => confirmed [15] => into [16] => your [17] => CoinPayments [18] 
 => Wallet. [19] => The [20] => deposit [21] => was [22] => received [23] => 
 on [24] => an address [25] => with [26] => 
 transaction [27] => ID [28] => 
 an txid.Thank [29] 
 => you [30] => for [31] => using [32] => CoinPayments.net!Support [33] => 
 is [34] => available [35] => at: [36] => https://www.coinpayments.net/help- 
 support-----BEGIN [37] => PGP [38] => SIGNATURE----- 
 END [39] => PGP [40] => SIGNATURE----- )

Now i try to fetch most recent email using imap, delete it and put variables in deposits table.

   <?php
   $hostname = "{imap.gmail.com:993/imap/ssl/novalidate-cert}Inbox";
   $username = 'username';
   $password = 'password';

    $inbox = imap_open($hostname,$username,$password) or die('Cannot connect: ' . imap_last_error());

  $emails = imap_search($inbox,'ALL');


  if($emails)
 {
$output = '';

rsort($emails);

  $email_number = $emails[0];
{


    $message = quoted_printable_decode(imap_fetchbody($inbox,$email_number,1.1)); 
    if($message == '')
    {
        $message = (imap_fetchbody($inbox,$email_number,1));
        $str =  "$message";
        $explode = (explode(" ",$str));
        $check = $explode[20];
        if ($check =='deposit') {
            $address = $explode[24];
            $textsplit = "$explode[28]";
            $split = (explode(".",$textsplit));
            $txid = $split[0];
            $signature = $explode[38];
            $date = date("Y-m-d");
            require ('setup.php');
                $conn = new mysqli($localhost, $hostuser, $hostpass, $hostdb) or die("conn died");
                $query1 = "SELECT user FROM addresses WHERE address = '$address'";  //Get username so i put it with txid in deposits table
               $result = $conn->query($query1);
                if ($result) {

             while ($row = mysqli_fetch_array($result)) {
              $user = $row['user'];
             }
                $query = "INSERT INTO deposits(tx, date, user, signature) VALUES('$txid', '$date', '$user', '$signature')";
                $result = mysqli_query($conn, $query);

    if($result) {
        echo 'inserted';
        $dl = imap_delete($inbox, $email_number);
        if ($dl) {
            echo 'deleted';
        }
        else {
            die('cant insert');
        }
    }
    else {
        die('failed1');
    }
        }
       else
       {
           die('failed');
       }


    }
}       
}
}

But at last i get "failed1". I dont think there is any error. Please help me if you can =)

  • 写回答

1条回答 默认 最新

  • dtr84664 2018-07-21 08:43
    关注

    For this query here:

    $result = mysqli_query($conn, $query);
    

    Replace it with:

    $result = $conn->query($query);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用