17
17
use SmtpValidatorEmail \Mx \Mx ;
18
18
use SmtpValidatorEmail \Smtp \Smtp ;
19
19
20
+
20
21
/**
21
22
* Class ValidatorEmail
22
23
* @package SmtpValidatorEmail
@@ -87,7 +88,6 @@ public function __construct($emails = array(), $sender = '', $options = array())
87
88
$ emailBag ->add ((array )$ emails );
88
89
$ domainBag = $ this ->setEmailsDomains ($ emailBag );
89
90
$ this ->domains = $ domainBag ->all ();
90
-
91
91
}
92
92
93
93
if (!empty ($ sender )) {
@@ -131,7 +131,7 @@ public function __construct($emails = array(), $sender = '', $options = array())
131
131
132
132
} catch (ExceptionNoConnection $ e ) {
133
133
// unable to connect to host, so these addresses are invalid?
134
- $ this ->setDomainResults ($ users , $ dom , 0 );
134
+ $ this ->setDomainResults ($ users , $ dom , 0 , ' unable to connect to host ' );
135
135
}
136
136
}
137
137
@@ -147,29 +147,34 @@ public function __construct($emails = array(), $sender = '', $options = array())
147
147
// try issuing MAIL FROM
148
148
if (!($ smtp ->mail ($ this ->fromUser . '@ ' . $ this ->fromDomain ))) {
149
149
// MAIL FROM not accepted, we can't talk
150
- $ this ->setDomainResults ($ users , $ dom , $ options ['noCommIsValid ' ]);
150
+ $ this ->setDomainResults ($ users , $ dom , $ options ['noCommIsValid ' ], ' MAIL FROM not accepted ' );
151
151
}
152
152
153
153
/**
154
154
* if we're still connected, proceed (cause we might get
155
155
* disconnected, or banned, or greylisted temporarily etc.)
156
156
* see mail() for more
157
157
*/
158
- if ($ smtp ->isConnect ()) {
158
+ if ( $ smtp ->isConnect ()) {
159
159
160
160
$ smtp ->noop ();
161
161
162
162
// Do a catch-all test for the domain always.
163
163
// This increases checking time for a domain slightly,
164
164
// but doesn't confuse users.
165
- $ isCatchallDomain = $ smtp ->acceptsAnyRecipient ($ dom );
165
+ try {
166
+ $ isCatchallDomain = $ smtp ->acceptsAnyRecipient ($ dom );
167
+ }catch (\Exception $ e ) {
168
+ $ this ->setDomainResults ($ users , $ dom , $ options ['catchAllIsValid ' ], 'error while on CatchAll test: ' .$ e );
169
+ }
170
+
166
171
167
172
// if a catchall domain is detected, and we consider
168
173
// accounts on such domains as invalid, mark all the
169
174
// users as invalid and move on
170
175
if ($ isCatchallDomain ) {
171
176
if (!$ options ['catchAllIsValid ' ]) {
172
- $ this ->setDomainResults ($ users , $ dom , $ options ['catchAllIsValid ' ]);
177
+ $ this ->setDomainResults ($ users , $ dom , $ options ['catchAllIsValid ' ], ' catch all detected ' );
173
178
continue ;
174
179
}
175
180
}
@@ -182,8 +187,7 @@ public function __construct($emails = array(), $sender = '', $options = array())
182
187
$ address = $ user . '@ ' . $ dom ->getDomain ();
183
188
$ this ->results [$ address ] = $ smtp ->rcpt ($ address );
184
189
185
- if ($ this ->results [$ address ] == 1 )
186
- {
190
+ if ($ this ->results [$ address ] == 1 ) {
187
191
$ loopStop = 1 ;
188
192
}
189
193
$ smtp ->noop ();
@@ -201,12 +205,11 @@ public function __construct($emails = array(), $sender = '', $options = array())
201
205
}
202
206
203
207
} else {
204
-
205
208
// we didn't get a good response to helo and should be disconnected already
206
- $ this ->setDomainResults ($ users , $ dom , $ options ['noCommIsValid ' ]);
207
-
209
+ $ this ->setDomainResults ($ users , $ dom , $ options ['noCommIsValid ' ],'bad response on helo ' );
208
210
}
209
-
211
+ } else {
212
+ $ this ->setDomainResults ($ users , $ dom , 0 ,'no connection ' );
210
213
}
211
214
212
215
if ($ options ['domainMoreInfo ' ]) {
@@ -279,15 +282,19 @@ public function setSender($email)
279
282
* @param array $users Array of users (usernames)
280
283
* @param Domain $domain The domain
281
284
* @param int $val Value to set
285
+ * @param String $info Optional , can be used to give additional information about the result
282
286
*/
283
- private function setDomainResults ($ users , Domain $ domain , $ val )
287
+ private function setDomainResults ($ users , Domain $ domain , $ val, $ info = '' )
284
288
{
285
289
if (!is_array ($ users )) {
286
290
$ users = (array )$ users ;
287
291
}
288
292
289
293
foreach ($ users as $ user ) {
290
- $ this ->results [$ user . '@ ' . $ domain ->getDomain ()] = $ val ;
294
+ $ this ->results [$ user . '@ ' . $ domain ->getDomain ()] = [
295
+ 'result ' => $ val ,
296
+ 'info ' => $ info
297
+ ];
291
298
}
292
299
}
293
300
}
0 commit comments