I have written a code for sending emails to multiple emailaddress in the controller, but I guess I have written it wrong, and I am not sure if I wrote the clear email in the write part of the forloop as well. Sorry this might be a easy question but I am some what new in this field.
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('[email protected]', '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);
}
}
I am getting 2 arrays from the model, including Email and duedate.
Error picture
, and 
Problem is here,
$result = json_decode(json_encode($foo[0]), true);
foreach ($foo as $result){
^// overwriting previous variable
If $result is object, access using ->
$result->email;
If its an array
$result['email'];
EDIT
you are getting only one row because,
$result = json_decode(json_encode($foo[0]), true);
^
you are considering only first index., remove that 0 as index.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With