kodus /
mail
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Kodus\Mail\SMTP\Connector; |
||
| 4 | |||
| 5 | use Kodus\Mail\SMTP\SMTPClient; |
||
| 6 | use Kodus\Mail\SMTP\SMTPConnector; |
||
| 7 | use Kodus\Mail\SMTP\SMTPException; |
||
| 8 | |||
| 9 | class SocketConnector implements SMTPConnector |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var string SMTP hostname |
||
| 13 | */ |
||
| 14 | protected $host; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var int SMTP server port-number |
||
| 18 | */ |
||
| 19 | protected $port; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param string $host SMTP host-name |
||
| 23 | * @param int $port SMTP port-number |
||
| 24 | */ |
||
| 25 | 2 | public function __construct(string $host, int $port = 25) |
|
| 26 | { |
||
| 27 | 2 | $this->host = $host; |
|
| 28 | 2 | $this->port = $port; |
|
| 29 | 2 | } |
|
| 30 | |||
| 31 | 2 | public function connect(string $client_domain): SMTPClient |
|
| 32 | { |
||
| 33 | 2 | $socket = @fsockopen($this->host, $this->port); |
|
| 34 | |||
| 35 | 2 | if (! $socket) { |
|
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 36 | throw new SMTPException("Could not open SMTP Port."); |
||
| 37 | } |
||
| 38 | |||
| 39 | 2 | $client = new SMTPClient($socket); |
|
| 40 | |||
| 41 | 2 | $client->sendEHLO($client_domain); |
|
| 42 | |||
| 43 | 2 | return $client; |
|
| 44 | } |
||
| 45 | } |
||
| 46 |