标签:codeigniter for-loop php controller
我已经编写了用于将电子邮件发送到控制器中多个电子邮件地址的代码,但是我想我写错了,而且我不确定我是否也在forloop的写部分中写了清晰的电子邮件.抱歉,这可能是一个简单的问题,但我对这个领域有什么新认识.
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个数组,包括Email和Duedate.
错误图片和
解决方法:
问题在这里
$result = json_decode(json_encode($foo[0]), true);
foreach ($foo as $result){
^// overwriting previous variable
如果$result是object,则使用->访问.
$result->email;
如果是数组
$result['email'];
编辑
您只能得到一行,因为,
$result = json_decode(json_encode($foo[0]), true);
^
您只考虑第一个索引.请删除该0作为索引.
标签:codeigniter,for-loop,php,controller 来源: https://codeday.me/bug/20191027/1945695.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。