简体   繁体   中英

Sending html email in Codeigniter

I am sending a template html in codeigniter and in fact my email is working perfectly fine.

My problem is how i send a template of html to the email. I got an error because of the variables passed to.

public function send_email_accountability($C11, $C4, $C8,$C12)
{
    date_default_timezone_set('Asia/Manila');
    $message = $this->load->view('sample_html',$data,TRUE); 
    $this->load->library('email');
    $this->email->set_mailtype("html");
    $this->email->from('noreply@email.com', 'EMAIL');
    $this->email->to($C11); 
    $this->email->subject('Accountability for'. $C12);
    $this->email->message($message);
}

I receive the email but inside the email is php error because the $data cannot be passed to. I looked at other stackoverflow problems and it didn't help my problem.

public function send_email_accountability($C11, $C4, $C8,$C12)
{
    date_default_timezone_set('Asia/Manila');
    $this->load->library('email');
    $data['title']='HELLO WORLD';
    $this->email->from('noreply@email.com', 'EMAIL');
    $this->email->to($C11); 
    $this->email->subject('Accountability for'. $C12);
    $this->email->set_mailtype("html");
    $msg = $this->load->view('sample_html',$data,TRUE);
    $this->email->message($msg);
    $this->email->send();
}


Try this one

you are using a data array ($data) to the view, but no values is assigned to it, just assign any value to array to avoid the error,

$data['logo_img'] = 'images/logo.png';     // add this line before loading the view

This logo image is located as $logo_img in the view sample_html ...

use PHPmailer . It will help You. I also use it. You can get all information about PHPmailer from here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM