Skip to content
World Wide Web Server edited this page Jul 4, 2012 · 32 revisions

Well I wanted to call this library/plugin Freak_Swift_Mailer, but then... somebody killed my creativity...

Anyway, this is my solution for using SWIFT MAILER library with CI.


[b]RESOURCES:[/b]

=> [url=http://www.codeigniter.com/forums/viewthread/3049/]FORUM[/url]

=> official [url=http://www.swiftmailer.org/]SWIFT MAILER WEBSITE[/url]

=> [url=http://www.4webby.com/freakauth/]4webby.com[/url] for tutorials

[b]Author: Daniel Vecchiato (danfreak) website: [url=http://www.4webby.com/freakauth/]http://www.4webby.com[/url] The original Swift Mailer package has been released by Chris Corbyn [url=http://www.swiftmailer.org/]http://www.swiftmailer.org/[/url][/b]

  • @license GNU Lesser General Public License

*/

[b]

REQUIREMENTS:

[/b]

[b]

INSTALLATION:

[/b]

  1. download SWIFT MAILER from [url=http://www.swiftmailer.org/]SWIFT MAILER website[/url] (choose PHP4 or PHP5 version according to your needs)

  2. unzip Swift-X.0.X-phpX.zip in a local folder

  3. create a folder called [b]my_classe[/b] in your [b]system/application[/b] directory

  4. copy the files [b]INSIDE[/b] the folder [b]Swift-X.0.X-phpX/lib/[/b] in your CodeIgniter installation directory

  5. enable hooks in your [b]application/config/config.php[/b] file [code] /* |-------------------------------------------------------------------------- | Enable/Disable System Hooks |-------------------------------------------------------------------------- | | If you would like to use the "hooks" feature you must enable it by | setting this variable to TRUE (boolean). See the user guide for details. | */ $config['enable_hooks'] = TRUE; [/code]

  6. add the following lines in [b]application/config/config.php[/b] [code] $hook['pre_controller'][] = array( 'class' => 'MyClasses', 'function' => 'index', 'filename' => 'MyClasses.php', 'filepath' => 'hooks' ); [/code]

  7. build a controller to test that every works fine ([url=http://www.swiftmailer.org/wikidocs/v3/basic]example taken here[/url]) [code] <?php class Mail extends Controller { function Mail() { parent::Controller();

    }

    function index() { //Load in the files we'll need require_once "Swift.php"; require_once "Swift/Connection/SMTP.php";

     //Start Swift
     $swift =& new Swift(new Swift_Connection_SMTP("your.smtp.com"));
      
     //Create the message
     $message =& new Swift_Message("My subject", "My body");
      
     //Now check if Swift actually sends it
     if ($swift->send($message, "[email protected]", "[email protected]")) echo "Sent";
     else echo "Failed";
    

    } }

?> [/code]

  1. now build other controllers/methods to suit your needs. Check out the [url=http://www.swiftmailer.org/wikidocs/]SWIFT MAILER DOCUMENTATION[/url]

[b]IMPORTANT NOTICE: [/b] use the examples in the documentation, but change [code] //Load in the files we'll need require_once "lib/Swift.php"; require_once "lib/Swift/Connection/SMTP.php"; [/code]

to

[code] //Load in the files we'll need require_once "Swift.php"; require_once "Swift/Connection/SMTP.php"; [/code]

  1. HAPPY CODING!

Category:Libraries::Email Category:Plugin::Swift Mailer

Clone this wiki locally