I want to send an email to user from my application with the content of the email loaded from a view . This is the code i’ve tried out till now:
$toemail = "user@email.id";
$subject = "Mail Subject is here";
$mesg = $this->load->view('template/email');
$this->load->library('email');
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->to($toemail);
$this->email->from($fromemail, "Title");
$this->email->subject($subject);
$this->email->message($mesg);
$mail = $this->email->send();
$this->load->library('email');within the controller as well for the email in CI to work.$fromemailis not initialized.Working Code:
Edit:
$mesg = $this->load->view('template/email',true);should be having the true as pointed out by lycanian. By setting it as true , it doesn’t send data to the output stream but it will return as a string.Edit:
$this->load->view();need a second parameter with data or empty like$mesg = $this->load->view(view,data,true);, if not it wont work