1 | <?php |
||
8 | class SMTPClient implements LoggerAwareInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var resource SMTP socket handle |
||
12 | */ |
||
13 | protected $socket; |
||
14 | |||
15 | /** |
||
16 | * @var LoggerInterface|null |
||
17 | */ |
||
18 | protected $logger; |
||
19 | |||
20 | /** |
||
21 | * @var string |
||
22 | */ |
||
23 | protected $eol = "\r\n"; |
||
24 | |||
25 | /** |
||
26 | * @var string last command issued to the SMTP server |
||
27 | */ |
||
28 | protected $last_command; |
||
29 | |||
30 | /** |
||
31 | * @var string last result received from the SMTP server |
||
32 | */ |
||
33 | protected $last_result; |
||
34 | |||
35 | /** |
||
36 | * @param resource $socket SMTP socket |
||
37 | * |
||
38 | * @throws UnexpectedCodeException on missing welcome message |
||
39 | */ |
||
40 | 2 | public function __construct($socket) |
|
50 | |||
51 | /** |
||
52 | * Send the `QUIT` command and close the SMTP socket |
||
53 | */ |
||
54 | 2 | public function __destruct() |
|
60 | |||
61 | /** |
||
62 | * @see http://www.php-fig.org/psr/psr-3/ |
||
63 | * |
||
64 | * @param LoggerInterface|null $logger PSR-3 compliant Logger implementation |
||
65 | * |
||
66 | * @return void |
||
67 | */ |
||
68 | 1 | public function setLogger(LoggerInterface $logger = null) |
|
72 | |||
73 | /** |
||
74 | * Send the `EHLO` command and checks the response |
||
75 | * |
||
76 | * @param string $client_domain |
||
77 | */ |
||
78 | 2 | public function sendEHLO($client_domain) |
|
82 | |||
83 | /** |
||
84 | * Send the `STARTTLS` command and initialize stream socket encryption. |
||
85 | * |
||
86 | * @param int $crypto_method one of the STREAM_CRYPTO_METHOD_* constants (defined by PHP) |
||
87 | * |
||
88 | * @throws SMTPException on failure |
||
89 | */ |
||
90 | public function sendSTARTTLS($crypto_method) |
||
98 | |||
99 | /** |
||
100 | * Write an SMTP command (with EOL) to the SMTP socket, and read the status code. |
||
101 | * |
||
102 | * @param string $command |
||
103 | * @param string|null $expected_code optional expected response status-code |
||
104 | * |
||
105 | * @return string SMTP status code |
||
106 | * |
||
107 | * @throws UnexpectedCodeException |
||
108 | */ |
||
109 | 2 | public function sendCommand($command, $expected_code = null) |
|
125 | |||
126 | /** |
||
127 | * @param string $sender sender e-mail address |
||
128 | * @param string[] $recipients list of recipient e-mail addresses |
||
129 | * @param callable $write function (resource $resouce) : void |
||
130 | */ |
||
131 | 2 | public function sendMail($sender, array $recipients, callable $write) |
|
137 | |||
138 | /** |
||
139 | * Send the `MAIL FROM` command and check the response |
||
140 | * |
||
141 | * @param string $sender sender e-mail address |
||
142 | */ |
||
143 | 2 | protected function sendMailFromCommand($sender) |
|
147 | |||
148 | /** |
||
149 | * Send a series of `RCPT TO` commands and check each response |
||
150 | * |
||
151 | * @param string[] $recipients list of recipient e-mail addresses |
||
152 | */ |
||
153 | 2 | protected function sendRecipientCommands(array $recipients) |
|
159 | |||
160 | /** |
||
161 | * Send the `DATA` command, expose the filtered stream to a callback for writing |
||
162 | * the data, terminate the data-stream, and check the response. |
||
163 | * |
||
164 | * @param callable $write function (resource $resouce) : void |
||
165 | * |
||
166 | * @throws SMTPException |
||
167 | */ |
||
168 | 2 | protected function sendDataCommands(callable $write) |
|
180 | |||
181 | /** |
||
182 | * Read the SMTP status code |
||
183 | * |
||
184 | * @return string SMTP status code |
||
185 | * |
||
186 | * @throws SMTPException |
||
187 | */ |
||
188 | 2 | protected function readCode() |
|
202 | |||
203 | /** |
||
204 | * @param string $message |
||
205 | */ |
||
206 | 2 | protected function log($message) |
|
212 | } |
||
213 |