【问题标题】:Cannot retrieve data to send on email with codeigniter无法使用 codeigniter 检索要通过电子邮件发送的数据
【发布时间】:2016-03-22 06:34:00
【问题描述】:

我之前也遇到过类似的问题,但它已经解决了,但即使在知道它是如何完成的之后,这还是非常令人困惑。所以我在控制器上编写了一个函数,它从 MySQL 数据库接收数据并使用代码点火器函数发送电子邮件。所以这里是控制器代码

 public function sendEmailToNewBorrower() {
    //fetch tha data from the database 
        $this->load->model('payment_plan');
        $foo = $this->payment_plan->getInfoToNotifyBorrowerForNewLoan();
        $result = json_decode(json_encode($foo), true);

        $this->load->library('email'/*, $config*/);
        $this->email->from('info@loaners.club', 'Loaners CLub');
        $this->email->to($result->Email);
        $this->email->subject('Consumer Credit Information');
        //$msg = $this->load->view('mypayment_view', '', true);
        $name = ($result->Fullname);
        $TotalAmountOfLoan = ($result->capital_payment); 
        $BorrowedAmount = ($result->borrowed_amount);
        $LCcomission = ($result->amount_invoiced);
        $Interest = ($result->interest_payment);
        $Cur = ($result->Abbreviation);
        $duedate = ($result->duedate);
        $installment = ($result->instalmentnbr);
        $BorrowerInterest = ($result->Interest);
        $overdueInterest = ($result->overdue_interest);
        $APR = ($result->total_payment);
        $BorrowingPeriod = ($result->Loantime);
        $msg1 =('https://apps.facebook.com/jussintestins/index.php'); 
        $this->email->message(
            'Hello! '.$name."\n"."\n"
            .'You have  a loan and we would like you to know all information about your loan. '."\n"."\n"."\n"
            .'Loan information'."\n"."\n"

            .'Total Borrowed Amount:  '.$cur.' '.$BorrowedAmount.'.'."\n"
            .'Loaners Club Comission: '.$cur.' '.$LCcomission.'.'."\n"
            .'Total Payment :  '.$cur.' '.$TotalAmountOfLoan.'.'."\n"
            .'Installments :'.$installment.'.'."\n"
            .'Interest Rate :'.$BorrowerInterest.'%.'."\n"
            .'Interest Paid :'.$Interest.'%.'."\n"
            .'Over due payment interest :'.$overdueInterest.'%.'."\n"
            .'Your borrowing period: '.$BorrowingPeriod.'.'."\n"

                ."\n"."\n"
            .'You have the right to withdraw the money'."\n"
            .'You can click this link to pay your loan.'.'Something heere'.'.'."\n"."\n"."\n"
            .'Thank you for using Loaners Club and we would like you to see all our other offers here '.$msg1."\n"."\n"
            .'For more information contact info@loanersclub.com  '
            ."\n"
            ."\n"
            .'Have a great day! Loaners Club'
          );  
    $returnvalue = $this->email->send();
  if(!$returnvalue) {
       alert("email failed to send");
    } else {
     $data=array('notified_borrower'=>current_time,'current_time'=>date('Y-m-d H:i:s'));
     $this->db->update('payment_plan', $data);
       }
}

所以当我调试程序时,它显示我确实从数据库中获取了数据。 但是当我检查 $result 时,它向我显示了这一点。

所以现在我不知道为什么会发生这种情况,因为我没有在那里存储任何信息,但我确实收到一个错误,说无法读取长度。还有一点就是最后的更新部分也没有更新。

【问题讨论】:

    标签: php mysql codeigniter model-view-controller controller


    【解决方案1】:

    我已经查看了您的功能并进行了更正。请检查,并记下我留下的cmets。

    public function sendEmailToNewBorrower() {
        //fetch tha data from the database
        $this->load->model('payment_plan');
        $foo = $this->payment_plan->getInfoToNotifyBorrowerForNewLoan();
        /**
         * If @foo is json
         * json_decode($foo); will return an Object. json_decode($foo, true) will return an array
         */
        //$result = json_decode($foo);
        $result = json_decode(json_encode($foo[0]), true);
    
        $this->load->library('email'/*, $config*/); //Why is the $config off here? make sure you have a proper config loaded for your email library
        $this->email->from('info@loaners.club', 'Loaners CLub');
        $this->email->to($result->Email);
        $this->email->subject('Consumer Credit Information');
        //$msg = $this->load->view('mypayment_view', '', true);
        $name               = $result['Fullname'];
        $TotalAmountOfLoan  = $result['capital_payment'];
        $BorrowedAmount     = $result['borrowed_amount'];
        $LCcomission        = $result['amount_invoiced'];
        $Interest           = $result['interest_payment'];
        $Cur                = $result['Abbreviation'];
        $duedate            = $result['duedate'];
        $installment        = $result['instalmentnbr'];
        $BorrowerInterest   = $result['Interest'];
        $overdueInterest    = $result['overdue_interest'];
        $APR                = $result['total_payment'];
        $BorrowingPeriod    = $result['Loantime'];
    
        $msg1 =('https://apps.facebook.com/jussintestins/index.php');
        $this->email->message(
            'Hello! '.$name."\n"."\n"
            .'You have  a loan and we would like you to know all information about your loan. '."\n"."\n"."\n"
            .'Loan information'."\n"."\n"
            //You are trying to add a variable named $Cur as $cur. changed it to $Cur..
            .'Total Borrowed Amount:  '.$Cur.' '.$BorrowedAmount.'.'."\n"
            .'Loaners Club Comission: '.$Cur.' '.$LCcomission.'.'."\n"
            .'Total Payment :  '.$Cur.' '.$TotalAmountOfLoan.'.'."\n"
            .'Installments :'.$installment.'.'."\n"
            .'Interest Rate :'.$BorrowerInterest.'%.'."\n"
            .'Interest Paid :'.$Interest.'%.'."\n"
            .'Over due payment interest :'.$overdueInterest.'%.'."\n"
            .'Your borrowing period: '.$BorrowingPeriod.'.'."\n"
    
            ."\n"."\n"
            .'You have the right to withdraw the money'."\n"
            .'You can click this link to pay your loan.'.'Something heere'.'.'."\n"."\n"."\n"
            .'Thank you for using Loaners Club and we would like you to see all our other offers here '.$msg1."\n"."\n"
            .'For more information contact info@loanersclub.com  '
            ."\n"
            ."\n"
            .'Have a great day! Loaners Club'
        );
        $returnvalue = $this->email->send();
        if(!$returnvalue) {
            alert("email failed to send");
        } else {
            $data=array('notified_borrower'=>current_time,'current_time'=>date('Y-m-d H:i:s'));
            $this->db->update('payment_plan', $data);
        }
    }
    

    【讨论】:

    • 在这个函数中 $result = json_decode($foo);结果说它的 null 和 foo 说它有数组,所以是的,它仍然不工作。
    • 不应该是 ($foo, true) 因为它从 db 中返回一个数组,对吗?
    • 你能在 $foo 上做 print_r 并发布结果吗
    • 我把屏幕上出现的错误作为图片放在了最上方
    • @Farhana 你能给我 Teamviewer 访问权限吗,目前还不清楚发生了什么
    【解决方案2】:

    根据您给定的图像$foo 是数组而不是 json,因为 json_decode 已经给定数组所以不需要json_decode($foo); 您可以直接使用如下

    $foo = $this->payment_plan->getInfoToNotifyBorrowerForNewLoan();
    $result = json_decode($foo);
    

    【讨论】:

    • 我这样做了,但现在我得到了 $name 和所有其他值为 null 的值
    • 我得到这个错误 Uncaught TypeError: Cannot read property 'length' of undefined (10:41:23:735 | error, javascript)
    • 您好,需要添加like $result[0]->Fullname;
    • $result[0] 在所有地方?
    猜你喜欢
    • 2012-12-10
    • 2018-10-12
    • 1970-01-01
    • 2013-06-15
    • 2012-10-31
    相关资源
    最近更新 更多