我在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);
}
}
最佳答案
问题来了
$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/