CodeIgniter Forums

Full Version: Swiftmail Library for CodeIgniter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum


I was finding problems using the email library from CodeIgniter because the config/email.php file was not working the way it was supposed to, and InsiteFX told me on my topic that he was using Swiftmail, so wanted to use it to, but i knew that it get's a little messy to setup and use it so i created this small library to help me Smile

You can assign variables and use them on your email files like so

Hello {user},

This is to check if it {variable}!

The library itself:

How to use:
$this->email->assign('user', 'John Doe');
$this->email->assign('variable', 'Works');
$this->email->from( array('[email protected]' => 'Your name') );
$this->email->to( array('[email protected]' => 'His name') );
if ( ! $this->email->send())
    show_error('Email not sended :c');
} else {
    echo('Email sended!');      

You need to create the file config/email.php and set the variables there

$config['protocol']  = 'smtp';
$config['smtp_host'] = 'ssl://';
$config['smtp_port'] = 465;
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'your_password';
$config['charset']   = 'utf-8';
$config['mailtype']  = 'html';
$config['newline']   = "\r\n";

You need to edit the path to the Swiftmail installation on the top of the file Smile

Some ideas came from phpBB and from CodeIgniter !

El Forum

I would rename your library because it's the same as CodeIgniter's and may conflict with it!

El Forum

For what i need it doesn't conflict since it loads only this library not the CI one.

El Forum

Ok, but just pointing out you need to be careful with naming libraries.

El Forum

[eluser]Zaher Ghaibeh[/eluser]
have you consider trying swift-mailer spark library ?
i didnt use it yet ( am planing to Big Grin ) ..