1 | <?php declare(strict_types=1); |
||
5 | class KMail |
||
6 | { |
||
7 | const VERSION = '1.1'; |
||
8 | |||
9 | const RELEASE_DATE = '2017-06-26'; |
||
10 | |||
11 | private $bound; |
||
12 | |||
13 | private $header; |
||
14 | |||
15 | private $subject = '(No subject)'; |
||
16 | |||
17 | private $adress = []; |
||
18 | |||
19 | private $body; |
||
20 | |||
21 | public function __construct(string $text) |
||
26 | |||
27 | private function sendMailUtf8(string $adress, string $subject, string $message, string $header): bool |
||
32 | |||
33 | public function send(): ?\Exception |
||
34 | { |
||
35 | if (sizeof($this->adress) == 0) { |
||
36 | throw new \Exception('Отсутствует адресат'); |
||
37 | } |
||
38 | $this->getHeader(); |
||
39 | foreach ($this->adress as $adress) { |
||
40 | $this->sendMailUtf8($adress, $this->getSubject(), $this->getBody(), $this->getHeader()); |
||
41 | } |
||
42 | |||
43 | return null; |
||
44 | } |
||
45 | |||
46 | public function addAdress(string $mail): KMail |
||
51 | |||
52 | private function addBodyMessage(string $text): void |
||
60 | |||
61 | public function addFile(string $fileName, string $fileStream): KMail |
||
71 | |||
72 | private function endBody(): string |
||
76 | |||
77 | private function getBody(): string |
||
81 | |||
82 | private function bound(): string |
||
83 | { |
||
84 | if (!$this->bound) { |
||
85 | $this->bound = '_=_Multipart_Boundary_' . substr(md5(uniqid()), 0, 8); |
||
86 | } |
||
87 | |||
88 | return $this->bound; |
||
89 | } |
||
90 | |||
91 | public function setSubject(string $subject): KMail |
||
99 | |||
100 | private function getSubject(): string |
||
104 | |||
105 | private function getHeader(): string |
||
112 | |||
113 | public function debug(): void |
||
117 | } |
||
118 |