Mailer icon indicating copy to clipboard operation
Mailer copied to clipboard

KO3 E-mail Module

Basic Usage:

  1. Customize the congfiguration setting in /config/mailer.php

    array( 'transport' => 'smtp', 'options' => array ( 'hostname' => 'smtp.mail.com', 'username' => '[email protected]', 'password' => 'password', 'encryption'=> 'ssl', 'port' => '465', ), ), 'development' => array( 'transport' => 'smtp' ) );
  2. Create a class that extends the Mailer class and save it to /classes/mailer/class_name.php (Minus the Mailer_)

    config = Kohana::$environment; } public function welcome($args) { $this->to = array('[email protected]' => 'Tom'); $this->bcc = array('[email protected]' => 'Admin'); $this->from = array('[email protected]' => 'The Team'); $this->subject = 'Welcome!'; $this->attachments = array('/path/to/file/file.txt', '/path/to/file/file2.txt'); $this->data = $args; } }
  3. Create the view for the email and save it to /views/mailer/class_name/method_name.php (Minus the Mailer_)

    Welcome = $user['name']; ?>,

    We are glad you signed up for our web app. Hope you enjoy.

    The Team

  4. Use the Mailer_User class in one of your controllers

    public function action_submit() { $data = array( 'user' => array( 'name' => 'Tom' ) );

     Mailer::factory('user')->send_welcome();
    
     //you can also pass arguments to the mailer
     Mailer::factory('user')->send_welcome($data);
    
     //you can also use instance
     Mailer::instance('user')->send_welcome($data);
    
     //you can also pass arguments in factory
     Mailer::factory('user', 'welcome', $data);
    
     //you can also send direct from the controller
     Mailer::instance()
     	->to('[email protected]')
     	->from('[email protected]')
     	->subject('Welcome!')
     	->html('Welcome!')
     	->send();
    

    }