Skip to content

Commit fa03556

Browse files
committed
SmtpMailer: Fix for servers which sends 250-AUTH only through encrypted connections (#67)
1 parent cb6d72c commit fa03556

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/Mail/SmtpMailer.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,8 @@ protected function connect(): void
155155
stream_set_timeout($this->connection, $this->timeout, 0);
156156
$this->read(); // greeting
157157

158-
$this->write("EHLO $this->clientHost");
159-
$ehloResponse = $this->read();
160-
if ((int) $ehloResponse !== 250) {
161-
$this->write("HELO $this->clientHost", 250);
162-
}
163-
164158
if ($this->secure === 'tls') {
159+
$this->write("EHLO $this->clientHost", 250);
165160
$this->write('STARTTLS', 220);
166161
if (!stream_socket_enable_crypto(
167162
$this->connection,
@@ -170,7 +165,18 @@ protected function connect(): void
170165
)) {
171166
throw new SmtpException('Unable to connect via TLS.');
172167
}
173-
$this->write("EHLO $this->clientHost", 250);
168+
$this->write("EHLO $this->clientHost");
169+
$ehloResponse = $this->read();
170+
if ((int) $ehloResponse !== 250) {
171+
throw new SmtpException('SMTP server did not accept EHLO with error: ' . trim($response));
172+
}
173+
174+
} else {
175+
$this->write("EHLO $this->clientHost");
176+
$ehloResponse = $this->read();
177+
if ((int) $ehloResponse !== 250) {
178+
$this->write("HELO $this->clientHost", 250);
179+
}
174180
}
175181

176182
if ($this->username != null && $this->password != null) {

0 commit comments

Comments
 (0)