I had a similar problem before but it was fixed but even after getting to know how its done this is very confusing. So I have a function written on a controller which receives data from MySQL database and sends an email using code igniter functions. So here is the controller code
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('[email protected]', '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 [email protected] '
."\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);
}
}
So when I debug the program it shows that I do get data from the database.
but when I check the $result it shows me this.

So right now I do not know why this is happening as I get no information stored there but I do get an error saying cannot read length. And one more thing is that the update part at the end also doesn't update.

I have reviewed your function and corrected it. please check, and take note of the comments i left.
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('[email protected]', '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 [email protected] '
."\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);
}
}
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