php - Forloop错误代码点火器

标签 php codeigniter for-loop controller

我在controller中写了一个发送邮件到多个emailaddress的代码,但是我想我写错了,我不确定我是否在forloop的write部分也写了clear email。抱歉,这可能是一个简单的问题,但我对这个领域有些了解。

public function sendEmailforUnpaidInvoiceFromDB() {
    //fetch tha data from the database 
    $this->load->model('invoice_page');
    $foo = $this->invoice_page->getInvoicesForNotification();
    $result = json_decode(json_encode($foo[0]), true);
    foreach ($foo as $result){
    $this->load->library('email');
    $this->email->from('helloworld@hello.com', 'HELLO');
    $this->email->to($result['Email']);
    $this->email->subject('Pay Payments');
    //$msg = $this->load->view('mypayment_view', '', true);
    $this->email->message('your due date is '.$result['duedate']);  
    $returnvalue = $this->email->send();


    if(!$returnvalue) {
       alert("email failed to send");
    } else {
     // $uptArray = array('customer_notified_dt' => NOW());
      //$this -> db -> update('invoice', $uptArray);
       }
    $this->email->clear(TRUE);   
    }
}

我从模型中得到 2 个数组,包括电子邮件和截止日期。 错误图片error using the url directly , 和 error using the button I placed

最佳答案

问题来了

$result = json_decode(json_encode($foo[0]), true);
foreach ($foo as $result){
                 ^// overwriting previous variable

如果$result是对象,使用->访问

 $result->email;

如果它是一个数组

 $result['email'];

编辑

你只得到一行,因为

$result = json_decode(json_encode($foo[0]), true);
                                       ^

您只考虑第一个索引。删除 0 作为索引。

关于php - Forloop错误代码点火器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34197626/

相关文章:

php - Sendgrid API - 错误的用户名/密码错误

php - PHP-如何将数据发送到另一个PHP-SQL页面并在同一页面上接收图表图像

php - if条件限制wordpress标题中的字数

php - 如何在 Travis 上启用 PHP redis 扩展

php - 如何在编辑 form_dropdown codeigniter 中显示所选项目

javascript - 在 codeigniter 错误中使用 jquery 加载页面内容

r - 如何在 R 中为这个嵌套的 for 循环编写更有效的代码?

php - CodeIgniter 中 select_avg() 的小数位数

java - 使用数组和列表的正确循环构造

python - 循环范围(0)