@@ -46,6 +46,9 @@ class SmtpMailer implements IMailer
4646 /** @var bool */
4747 private $ persistent ;
4848
49+ /** @var string */
50+ private $ clientHost ;
51+
4952
5053 public function __construct (array $ options = [])
5154 {
@@ -65,6 +68,13 @@ public function __construct(array $options = [])
6568 $ this ->port = $ this ->secure === 'ssl ' ? 465 : 25 ;
6669 }
6770 $ this ->persistent = !empty ($ options ['persistent ' ]);
71+ if (isset ($ options ['clientHost ' ])) {
72+ $ this ->clientHost = $ options ['clientHost ' ];
73+ } else {
74+ $ this ->clientHost = isset ($ _SERVER ['HTTP_HOST ' ]) && preg_match ('#^[\w.-]+\z# ' , $ _SERVER ['HTTP_HOST ' ])
75+ ? $ _SERVER ['HTTP_HOST ' ]
76+ : 'localhost ' ;
77+ }
6878 }
6979
7080
@@ -130,19 +140,18 @@ protected function connect(): void
130140 stream_set_timeout ($ this ->connection , $ this ->timeout , 0 );
131141 $ this ->read (); // greeting
132142
133- $ self = isset ($ _SERVER ['HTTP_HOST ' ]) && preg_match ('#^[\w.-]+\z# ' , $ _SERVER ['HTTP_HOST ' ]) ? $ _SERVER ['HTTP_HOST ' ] : 'localhost ' ;
134- $ this ->write ("EHLO $ self " );
143+ $ this ->write ("EHLO $ this ->clientHost " );
135144 $ ehloResponse = $ this ->read ();
136145 if ((int ) $ ehloResponse !== 250 ) {
137- $ this ->write ("HELO $ self " , 250 );
146+ $ this ->write ("HELO $ this -> clientHost " , 250 );
138147 }
139148
140149 if ($ this ->secure === 'tls ' ) {
141150 $ this ->write ('STARTTLS ' , 220 );
142151 if (!stream_socket_enable_crypto ($ this ->connection , true , STREAM_CRYPTO_METHOD_TLS_CLIENT )) {
143152 throw new SmtpException ('Unable to connect via TLS. ' );
144153 }
145- $ this ->write ("EHLO $ self " , 250 );
154+ $ this ->write ("EHLO $ this -> clientHost " , 250 );
146155 }
147156
148157 if ($ this ->username != null && $ this ->password != null ) {
0 commit comments