forked from kanema/Mailer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
84 lines (65 loc) · 1.99 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
Basic Usage:
1. Customize the congfiguration setting in /config/mailer.php
<?php
return array
(
'production' => array(
'transport' => 'smtp',
'options' => array
(
'hostname' => 'smtp.mail.com',
'username' => 'admin@theweapp.com',
'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_)
<?php defined('SYSPATH') or die('No direct script access.');
class Mailer_User extends Mailer {
publci function before()
{
// To set the config by environment
$this->config = Kohana::$environment;
}
public function welcome($args)
{
$this->to = array('tom@example.com' => 'Tom');
$this->bcc = array('admin@theweapp.com' => 'Admin');
$this->from = array('theteam@theweapp.com' => '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_)
<p>Welcome <?= $user['name']; ?>,</p>
<p>We are glad you signed up for our web app. Hope you enjoy.</p>
<p>The Team</p>
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('du@kanema.com.br')
->from('du@kanema.com.br')
->subject('Welcome!')
->html('Welcome!')
->send();
}