codeigniter Sending Email Send An HTML Email


But you don't just want a plain text email. You want a pretty html email.

Set your config file as html:

$config['mailtype'] = 'html';

If you want to pass data (like a username for example) to the html email, put them in an array:

$data = array('name' => $name, 
              'email' => $email,
              'phone' => $phone,
              'date' => $date);

Then when sending, point your 'message' to a view. Then pass your data array to it:

$this->email->message($this->load->view('new_user',$data, true));

In your application/view folder create your view.

In this case it's named 'new_user.php'.

You can style this anyway you'd like. Here's a quick example:

    <style type='text/css'>
        body {background-color: #CCD9F9;
             font-family: Verdana, Geneva, sans-serif}

        h3 {color:#4C628D}

        p {font-weight:bold}

    <h3>Hi <?php echo $name;?>,</h3>
    <h3>Thanks for contacting us.</h3> 

    <p>You've taken your first step into a larger world.</p>   
    <p>We really appreciate your interest.</p>