Skip to content

Commit d63efa1

Browse files
committed
Allow set stream context options
1 parent db20dc8 commit d63efa1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Mailer.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public function __construct(
6868
'host' => 'string',
6969
'port' => 'int',
7070
'tls' => 'bool',
71+
'options' => 'array',
7172
'username' => 'string|null',
7273
'password' => 'string|null',
7374
'charset' => 'string',
@@ -84,6 +85,13 @@ protected function makeConfig(#[SensitiveParameter] array $config) : array
8485
'host' => 'localhost',
8586
'port' => 587,
8687
'tls' => true,
88+
'options' => [
89+
'ssl' => [
90+
'allow_self_signed' => false,
91+
'verify_peer' => true,
92+
'verify_peer_name' => true,
93+
],
94+
],
8795
'username' => null,
8896
'password' => null,
8997
'charset' => 'utf-8',
@@ -115,6 +123,7 @@ protected function getConfig(string $key) : mixed
115123
'host' => 'string',
116124
'port' => 'int',
117125
'tls' => 'bool',
126+
'options' => 'array',
118127
'username' => 'string|null',
119128
'password' => 'string|null',
120129
'charset' => 'string',

src/Mailers/SMTPMailer.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@ protected function connect() : bool
3737
return $this->sendCommand('EHLO ' . $this->getConfig('hostname')) === 250;
3838
}
3939
$this->disconnect();
40-
$this->socket = @\fsockopen(
41-
$this->getConfig('host'),
42-
(int) $this->getConfig('port'),
40+
$this->socket = @\stream_socket_client(
41+
$this->getConfig('host') . ':' . $this->getConfig('port'),
4342
$errorCode,
4443
$errorMessage,
45-
(float) $this->getConfig('connection_timeout')
44+
(float) $this->getConfig('connection_timeout'),
45+
\STREAM_CLIENT_CONNECT,
46+
\stream_context_create($this->getConfig('options'))
4647
);
4748
if ($this->socket === false) {
4849
$this->addLog('', 'Socket connection error ' . $errorCode . ': ' . $errorMessage);

0 commit comments

Comments
 (0)