1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\View; |
4
|
|
|
|
5
|
|
|
use Nip\View; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Email |
9
|
|
|
* @package Nip\View |
10
|
|
|
*/ |
11
|
|
|
class Email extends View |
12
|
|
|
{ |
13
|
|
|
protected $_layout = "/layouts/email"; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var \Nip_Mailer|null |
17
|
|
|
*/ |
18
|
|
|
protected $_mail = null; |
19
|
|
|
|
20
|
|
|
public function __construct() |
21
|
|
|
{ |
22
|
|
|
$this->initMailer(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function initMailer() |
26
|
|
|
{ |
27
|
|
|
$this->_mail = new \Nip_Mailer(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function initBasePath() |
31
|
|
|
{ |
32
|
|
|
$this->setBasePath(MODULES_PATH . request()->getModuleName() . '/views/'); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $host |
37
|
|
|
* @param string $username |
38
|
|
|
* @param string $password |
39
|
|
|
* @return $this |
40
|
|
|
*/ |
41
|
|
|
public function authSMTP($host, $username, $password) |
42
|
|
|
{ |
43
|
|
|
$this->_mail->authSMTP($host, $username, $password); |
44
|
|
|
return $this; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Sets flag to show SMTP debugging information |
49
|
|
|
* @return $this |
50
|
|
|
*/ |
51
|
|
|
public function debugSMTP() |
52
|
|
|
{ |
53
|
|
|
$this->_mail->debugSMTP(); |
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $address |
59
|
|
|
* @param string|bool $name |
60
|
|
|
* @return $this |
61
|
|
|
*/ |
62
|
|
|
public function setFrom($address, $name = false) |
63
|
|
|
{ |
64
|
|
|
$this->_mail->setFrom($address, $name); |
65
|
|
|
return $this; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param string $address |
70
|
|
|
* @param string|bool $name |
71
|
|
|
* @return $this |
72
|
|
|
*/ |
73
|
|
|
public function addTo($address, $name = false) |
74
|
|
|
{ |
75
|
|
|
$this->_mail->addTo($address, $name); |
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param string $address |
81
|
|
|
* @param string $name |
82
|
|
|
* @return $this |
83
|
|
|
*/ |
84
|
|
|
public function addBCC($address, $name = '') |
85
|
|
|
{ |
86
|
|
|
$this->_mail->addBCC($address, $name); |
87
|
|
|
return $this; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $address |
92
|
|
|
* @param string|bool $name |
93
|
|
|
* @return $this |
94
|
|
|
*/ |
95
|
|
|
public function addReplyTo($address, $name = false) |
96
|
|
|
{ |
97
|
|
|
$this->_mail->addReplyTo($address, $name); |
98
|
|
|
return $this; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return $this |
103
|
|
|
*/ |
104
|
|
|
public function clearAllRecipients() |
105
|
|
|
{ |
106
|
|
|
$this->_mail->clearAllRecipients(); |
107
|
|
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param string $subject |
112
|
|
|
* @return $this |
113
|
|
|
*/ |
114
|
|
|
public function setSubject($subject) |
115
|
|
|
{ |
116
|
|
|
$this->_mail->setSubject($subject); |
117
|
|
|
return $this; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Adds attachment |
122
|
|
|
* |
123
|
|
|
* @param string $path |
124
|
|
|
* @param string $name |
125
|
|
|
* @return $this |
126
|
|
|
*/ |
127
|
|
|
public function addAttachment($path, $name = '') |
128
|
|
|
{ |
129
|
|
|
$this->_mail->addAttachment($path, $name); |
130
|
|
|
return $this; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @return mixed |
135
|
|
|
*/ |
136
|
|
|
public function send() |
137
|
|
|
{ |
138
|
|
|
if (!$this->getBody()) { |
139
|
|
|
$this->setBody($this->load($this->_layout, [], true)); |
140
|
|
|
} |
141
|
|
|
$this->_mail->setAltBody($this->getBody()); |
142
|
|
|
|
143
|
|
|
return $this->_mail->send(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @return mixed |
148
|
|
|
*/ |
149
|
|
|
public function getBody() |
150
|
|
|
{ |
151
|
|
|
return $this->_mail->getBody(); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
/** |
155
|
|
|
* @param string|null $body |
156
|
|
|
* @return $this |
157
|
|
|
*/ |
158
|
|
|
public function setBody($body) |
159
|
|
|
{ |
160
|
|
|
$this->_mail->setBody($body); |
161
|
|
|
return $this; |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param $layout |
166
|
|
|
*/ |
167
|
|
|
public function setLayout($layout) |
168
|
|
|
{ |
169
|
|
|
$this->_layout = $layout; |
170
|
|
|
} |
171
|
|
|
} |
172
|
|
|
|