1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace WZRD\Mail; |
4
|
|
|
|
5
|
|
|
use WZRD\Contracts\Mail\Message as MessageContract; |
6
|
|
|
|
7
|
|
|
class Message implements MessageContract |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* From addresses. |
11
|
|
|
* |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
protected $from; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Recipients addresses. |
18
|
|
|
* |
19
|
|
|
* @var array |
20
|
|
|
*/ |
21
|
|
|
protected $to; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* CC addresses. |
25
|
|
|
* |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
protected $cc; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* BCC addresses. |
32
|
|
|
* |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
protected $bcc; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Subject. |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
protected $subject; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Text. |
46
|
|
|
* |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
protected $text; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* HTML. |
53
|
|
|
* |
54
|
|
|
* @var string |
55
|
|
|
*/ |
56
|
|
|
protected $html; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Attachments. |
60
|
|
|
* |
61
|
|
|
* @var array |
62
|
|
|
*/ |
63
|
|
|
protected $attach; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Attachments with inline disposition. |
67
|
|
|
* |
68
|
|
|
* @var array |
69
|
|
|
*/ |
70
|
|
|
protected $inline; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Construct. |
74
|
|
|
*/ |
75
|
|
|
public function __construct() |
76
|
|
|
{ |
77
|
|
|
$this->text = $this->html = $this->subject = ''; |
78
|
|
|
$this->from = $this->to = $this->cc = $this->bcc = $this->attach = $this->inline = []; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Add a "from" address to the message. |
83
|
|
|
* |
84
|
|
|
* @param string $address |
85
|
|
|
* @param string $name |
86
|
|
|
* |
87
|
|
|
* @return self |
88
|
|
|
*/ |
89
|
|
|
public function addFrom($address, $name = null) |
90
|
|
|
{ |
91
|
|
|
$this->from[$address] = $name; |
92
|
|
|
|
93
|
|
|
return $this; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* Get "from" addresses. |
98
|
|
|
* |
99
|
|
|
* @return array |
100
|
|
|
*/ |
101
|
|
|
public function getFrom() |
102
|
|
|
{ |
103
|
|
|
return $this->from; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Add a recipient to the message. |
108
|
|
|
* |
109
|
|
|
* @param string $address |
110
|
|
|
* @param string $name |
111
|
|
|
* |
112
|
|
|
* @return self |
113
|
|
|
*/ |
114
|
|
|
public function addTo($address, $name = null) |
115
|
|
|
{ |
116
|
|
|
$this->to[$address] = $name; |
117
|
|
|
|
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Get recipients addresses. |
123
|
|
|
* |
124
|
|
|
* @return array |
125
|
|
|
*/ |
126
|
|
|
public function getTo() |
127
|
|
|
{ |
128
|
|
|
return $this->to; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Add a carbon copy to the message. |
133
|
|
|
* |
134
|
|
|
* @param string $address |
135
|
|
|
* @param string $name |
136
|
|
|
* |
137
|
|
|
* @return self |
138
|
|
|
*/ |
139
|
|
|
public function addCc($address, $name = null) |
140
|
|
|
{ |
141
|
|
|
$this->cc[$address] = $name; |
142
|
|
|
|
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Get carbon copies addresses. |
148
|
|
|
* |
149
|
|
|
* @return array |
150
|
|
|
*/ |
151
|
|
|
public function getCc() |
152
|
|
|
{ |
153
|
|
|
return $this->cc; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Add a blind carbon copy to the message. |
158
|
|
|
* |
159
|
|
|
* @param string $address |
160
|
|
|
* @param string $name |
161
|
|
|
* |
162
|
|
|
* @return self |
163
|
|
|
*/ |
164
|
|
|
public function addBcc($address, $name = null) |
165
|
|
|
{ |
166
|
|
|
$this->bcc[$address] = $name; |
167
|
|
|
|
168
|
|
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Get blind carbon copies addresses. |
173
|
|
|
* |
174
|
|
|
* @return array |
175
|
|
|
*/ |
176
|
|
|
public function getBcc() |
177
|
|
|
{ |
178
|
|
|
return $this->bcc; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* Set the subject of the message. |
183
|
|
|
* |
184
|
|
|
* @param string $subject |
185
|
|
|
* |
186
|
|
|
* @return self |
187
|
|
|
*/ |
188
|
|
|
public function setSubject($subject) |
189
|
|
|
{ |
190
|
|
|
$this->subject = $subject; |
191
|
|
|
|
192
|
|
|
return $this; |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Get subject. |
197
|
|
|
* |
198
|
|
|
* @return string |
199
|
|
|
*/ |
200
|
|
|
public function getSubject() |
201
|
|
|
{ |
202
|
|
|
return $this->subject; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Set the text of the message. |
207
|
|
|
* |
208
|
|
|
* @param string $text |
209
|
|
|
* |
210
|
|
|
* @return $this |
211
|
|
|
*/ |
212
|
|
|
public function setText($text) |
213
|
|
|
{ |
214
|
|
|
$this->text = $text; |
215
|
|
|
|
216
|
|
|
return $this; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Get text. |
221
|
|
|
* |
222
|
|
|
* @return string |
223
|
|
|
*/ |
224
|
|
|
public function getText() |
225
|
|
|
{ |
226
|
|
|
return $this->text; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Set the html of the message. |
231
|
|
|
* |
232
|
|
|
* @param string $html |
233
|
|
|
* |
234
|
|
|
* @return $this |
235
|
|
|
*/ |
236
|
|
|
public function setHtml($html) |
237
|
|
|
{ |
238
|
|
|
$this->html = $html; |
239
|
|
|
|
240
|
|
|
return $this; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Get HTML. |
245
|
|
|
* |
246
|
|
|
* @return string |
247
|
|
|
*/ |
248
|
|
|
public function getHtml() |
249
|
|
|
{ |
250
|
|
|
return $this->html; |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Attach a file to the message. |
255
|
|
|
* |
256
|
|
|
* @param string $file |
257
|
|
|
* @param array $options |
258
|
|
|
* |
259
|
|
|
* @return $this |
260
|
|
|
*/ |
261
|
|
|
public function attach($file, array $options = []) |
262
|
|
|
{ |
263
|
|
|
$this->attach[] = [$file, $options]; |
264
|
|
|
|
265
|
|
|
return $this; |
266
|
|
|
} |
267
|
|
|
|
268
|
|
|
/** |
269
|
|
|
* Get attachments. |
270
|
|
|
* |
271
|
|
|
* @return array |
272
|
|
|
*/ |
273
|
|
|
public function getAttachments() |
274
|
|
|
{ |
275
|
|
|
return $this->attach; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Attach a file to the message with inline disposition. |
280
|
|
|
* |
281
|
|
|
* @param string $file |
282
|
|
|
* @param array $options |
283
|
|
|
* |
284
|
|
|
* @return $this |
285
|
|
|
*/ |
286
|
|
|
public function inline($file, array $options = []) |
287
|
|
|
{ |
288
|
|
|
$this->inline[] = [$file, $options]; |
289
|
|
|
|
290
|
|
|
return $this; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Get inlines attachments. |
295
|
|
|
* |
296
|
|
|
* @return array |
297
|
|
|
*/ |
298
|
|
|
public function getInlines() |
299
|
|
|
{ |
300
|
|
|
return $this->inline; |
301
|
|
|
} |
302
|
|
|
} |
303
|
|
|
|