Skip to content
Derek Jones edited this page Jul 5, 2012 · 32 revisions

Category:Libraries

Code Igniter Richmail Library version 0.1

By Jan Willem Penterman jw@shapers.nl (Genoil on codeigniter.com) September 29, 2006

Version 0.1 - File:richmail-0.1.zip Version 0.2 - File:MY_Email.zip (Updated for Code Igniter 1.5.3)

Features:

This library extends the Email library, adding the following functions:

  • parse message body for images and add them as inline attachments
  • caches base64 encoded attachments for better performance

Installation:

The directories inside this archive should look familiar enough to you to know where to put the files...

Usage example:

;
// Load Richmail library instead of 'email':
$this->load->library('richmail');

// Since it subclasses CI_Email, this is all the same:
$this->richmail->from('sender@hostname.tld', 'Sender');
$this->richmail->to('recipient@hostname.tld', 'Recipient');            
$this->richmail->subject('Richmail test');

// Load message like any CI view:
$message = $this->load->view("richmail_view", array(), true);

// Convert message to have images reference inline content-id's.
// $message is passed by reference, but is also returned if you
// don't understand what I'm talking about.     
$this->richmail->inline($message);

// This is like Email again:
$this->richmail->message($message);
$this->richmail->send();

Notes:

  • Currently, only HTML image references are supported, no CSS. This is
    because inline CSS background images aren't supported very well in HTML email anyway.

  • The library assumes the host that serves the images is equal to the CI's base_url config var.

  • Base64 caching speeds up attachment building about 2 times, but I'm not too happy about having to duplicate the whole Email::_build_message() method.

  • It does not currently appear to support two inline images with the same name correctly - solve this by making sure all images have unique filenames.

Updated to work with CodeIgniter 1.5.3

This is the same Richmail class but updated to work with Code Igniter 1.5.3 File:MY_Email.zip

Just drop it into the /application/libraries directory and use as you would use the email class.

$this->load->library('email');
$email_config = array
(
'mailtype'    => 'html',
'multipart'    => 'related',
'base64cache' => false
);
$this->email->initialize($email_config);

// Since it subclasses CI_Email, this is all the same:
$this->email->from('your@your-site.com', 'Your Name');
$this->email->to('someone@some-site.com');
$this->email->cc('another@another-site.com');
$this->email->bcc('them@their-site.com');
$this->email->subject('Email Test');        
                
// Load message like any CI view:
$email_message = $this->load->view("email_message.html", array(), true);

// Convert message to have images reference inline content-id's.
$this->email->inline($email_message);

// This is like Email again:
$this->email->message($email_message);
$this->email->send(); 
Clone this wiki locally