Codeigniter how to html template for emails Codeigniter how to html template for emails codeigniter codeigniter

Codeigniter how to html template for emails


This is an example which i have done

 $data['map_to']=$this->input->post('map_to');        $event=$this->db->query("query");        if($event->num_rows()>0)        {            $data['event']=$event->row();            $data['map_from']=$event->row()->address2;        }        else        {        $data['event']=NULL;            }      $data['sender_mail'] = 'xx@xx.org';        $this->load->library('email');        $config = array (                  'mailtype' => 'html',                  'charset'  => 'utf-8',                  'priority' => '1'                   );        $this->email->initialize($config);        $this->email->from($data['sender_mail'], 'xxxx');        $this->email->to($mail);        $this->email->subject('Map Location');        $message=$this->load->view('map_mail_format',$data,TRUE);        $this->email->message($message);        $this->email->send();       

Here i am loading a view page called map_mail_format and passing values to that view page ($data) then assign that view page to a variable then send mail with that message


first you need to initialize config as

$config['charset'] = 'utf-8';$config['wordwrap'] = TRUE;$config['mailtype'] = 'html';$this->email->initialize($config);

after you load email library and then you can store your email view to a variable and mail it

$mailbody = $this->load->view('myfile', $data, true);


You may try this

$this->load->helper(array('email'));$this->load->library(array('email'));$this->email->set_mailtype("html");