@@ -46,6 +46,9 @@ class SmtpMailer implements IMailer
46
46
/** @var bool */
47
47
private $ persistent ;
48
48
49
+ /** @var string */
50
+ private $ clientHost ;
51
+
49
52
50
53
public function __construct (array $ options = [])
51
54
{
@@ -65,6 +68,13 @@ public function __construct(array $options = [])
65
68
$ this ->port = $ this ->secure === 'ssl ' ? 465 : 25 ;
66
69
}
67
70
$ 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
+ }
68
78
}
69
79
70
80
@@ -130,19 +140,18 @@ protected function connect(): void
130
140
stream_set_timeout ($ this ->connection , $ this ->timeout , 0 );
131
141
$ this ->read (); // greeting
132
142
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 " );
135
144
$ ehloResponse = $ this ->read ();
136
145
if ((int ) $ ehloResponse !== 250 ) {
137
- $ this ->write ("HELO $ self " , 250 );
146
+ $ this ->write ("HELO $ this -> clientHost " , 250 );
138
147
}
139
148
140
149
if ($ this ->secure === 'tls ' ) {
141
150
$ this ->write ('STARTTLS ' , 220 );
142
151
if (!stream_socket_enable_crypto ($ this ->connection , true , STREAM_CRYPTO_METHOD_TLS_CLIENT )) {
143
152
throw new SmtpException ('Unable to connect via TLS. ' );
144
153
}
145
- $ this ->write ("EHLO $ self " , 250 );
154
+ $ this ->write ("EHLO $ this -> clientHost " , 250 );
146
155
}
147
156
148
157
if ($ this ->username != null && $ this ->password != null ) {
0 commit comments