Email Module For Kohana 3.x and Koseven
Factory-based email class. This class is a simple wrapper around Swiftmailer.
Updates
- Based on the first email module for Kohana 3.x (shadowhand/email) with same method signatures
- Uses latest version of Swiftmailer (6.x) which removes ::newInstance() methods
- Adds support for using views similar to
View::factory(...)
as email body - Works with Koseven and Cascading filesystem
Installation
- Download to modules directory.
- Include it in
APPPATH/bootstrap.php
modules list:
Kohana::modules([
...
'email' => MODPATH.'kohana-email',
...
]);
- Go to your
DOCROOT
and include latest Swiftmailer
composer require swiftmailer/swiftmailer
Usage
Create new messages using the Email::factory($subject, $message)
method. Add recipients, add sender, send message:
$email = Email::factory('Hello, World', 'This is my body, it is nice.')
->to('person@example.com')
->from('you@example.com', 'My Name')
->send();
You can also add HTML to your message:
$email->message('<p>This is <em>my</em> body, it is <strong>nice</strong>.</p>', 'text/html');
You can also use a view and bind variables (like in the controllers)
$body = "This is a test from Kohana Email module";
$email = Email::factory('Hello, World')
->from('you@example.com', 'My Name')
->to('person@example.com')
->view('emails/message')
->bind('body', $body)
->send();
Additional recipients can be added using the to()
, cc()
, and bcc()
methods.
Additional senders can be added using the from()
and reply_to()
methods. If multiple sender addresses are specified, you need to set the actual sender of the message using the sender()
method. Set the bounce recipient by using the return_path()
method.
To access and modify the Swiftmailer message directly, use the raw_message()
method.
Configuration
Configuration is stored in config/email.php
. Options are dependant upon transport method used. Consult the Swiftmailer documentation for options available to each transport.
Alternatives
- https://github.com/svenbw/kohana-email - more modern, can use PHPMailer or Swiftmailer using drivers