@@ -155,13 +155,8 @@ protected function connect(): void
155
155
stream_set_timeout ($ this ->connection , $ this ->timeout , 0 );
156
156
$ this ->read (); // greeting
157
157
158
- $ this ->write ("EHLO $ this ->clientHost " );
159
- $ ehloResponse = $ this ->read ();
160
- if ((int ) $ ehloResponse !== 250 ) {
161
- $ this ->write ("HELO $ this ->clientHost " , 250 );
162
- }
163
-
164
158
if ($ this ->secure === 'tls ' ) {
159
+ $ this ->write ("EHLO $ this ->clientHost " , 250 );
165
160
$ this ->write ('STARTTLS ' , 220 );
166
161
if (!stream_socket_enable_crypto (
167
162
$ this ->connection ,
@@ -170,7 +165,18 @@ protected function connect(): void
170
165
)) {
171
166
throw new SmtpException ('Unable to connect via TLS. ' );
172
167
}
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
+ }
174
180
}
175
181
176
182
if ($ this ->username != null && $ this ->password != null ) {
0 commit comments