Vin_fugen
Vin_fugen

Reputation: 581

Codeigniter how to html template for emails

I'm using below code to send email from my codeigniter based website's contact form, to do that i'm using below codes in my controller,

    $entrydata['name']= $this->input->post('name');
    $entrydata['email']= $this->input->post('email');
    $entrydata['phone']= $this->input->post('phone');
    $entrydata['message']= $this->input->post('message');$msg = 'Email has sent successfully';

            $data['reset'] = TRUE;
            $this->load->library('email');
            $this->email->from(set_value('email'), set_value('name'));
            $this->email->to('[email protected]');
            $this->email->subject("Get a quote enquiry");
            $all = 'Name:' . set_value('name') ."\n". 'Email :' .' '. set_value('email') ."\n".'Phone :' .' '. set_value('phone') ."\n".'Message :' .' '. set_value('message'); $this->email->message($all);
            $s=$this->email->send();
            $data['message'] = $msg;

Did anyone know how to add custom email template that'll hold my conact form informations?

Upvotes: 7

Views: 24635

Answers (3)

BK004
BK004

Reputation: 392

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);

Upvotes: 6

abSiddique
abSiddique

Reputation: 12335

You may try this

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

Upvotes: 2

Juice
Juice

Reputation: 3063

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'] = '[email protected]';

        $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

Upvotes: 21

Related Questions