Skip to content

Commit f81435f

Browse files
committed
Merge pull request #11 from rubenCodeforges/patch-1
2 parents 620514a + 16cfb70 commit f81435f

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

lib/SmtpValidatorEmail/ValidatorEmail.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use SmtpValidatorEmail\Mx\Mx;
1818
use SmtpValidatorEmail\Smtp\Smtp;
1919

20+
2021
/**
2122
* Class ValidatorEmail
2223
* @package SmtpValidatorEmail
@@ -87,7 +88,6 @@ public function __construct($emails = array(), $sender = '', $options = array())
8788
$emailBag->add((array)$emails);
8889
$domainBag = $this->setEmailsDomains($emailBag);
8990
$this->domains = $domainBag->all();
90-
9191
}
9292

9393
if (!empty($sender)) {
@@ -131,7 +131,7 @@ public function __construct($emails = array(), $sender = '', $options = array())
131131

132132
} catch (ExceptionNoConnection $e) {
133133
// 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');
135135
}
136136
}
137137

@@ -147,29 +147,34 @@ public function __construct($emails = array(), $sender = '', $options = array())
147147
// try issuing MAIL FROM
148148
if (!($smtp->mail($this->fromUser . '@' . $this->fromDomain))) {
149149
// 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');
151151
}
152152

153153
/**
154154
* if we're still connected, proceed (cause we might get
155155
* disconnected, or banned, or greylisted temporarily etc.)
156156
* see mail() for more
157157
*/
158-
if ($smtp->isConnect()) {
158+
if ( $smtp->isConnect()) {
159159

160160
$smtp->noop();
161161

162162
// Do a catch-all test for the domain always.
163163
// This increases checking time for a domain slightly,
164164
// 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+
166171

167172
// if a catchall domain is detected, and we consider
168173
// accounts on such domains as invalid, mark all the
169174
// users as invalid and move on
170175
if ($isCatchallDomain) {
171176
if (!$options['catchAllIsValid']) {
172-
$this->setDomainResults($users, $dom, $options['catchAllIsValid']);
177+
$this->setDomainResults($users, $dom, $options['catchAllIsValid'],'catch all detected');
173178
continue;
174179
}
175180
}
@@ -182,8 +187,7 @@ public function __construct($emails = array(), $sender = '', $options = array())
182187
$address = $user . '@' . $dom->getDomain();
183188
$this->results[$address] = $smtp->rcpt($address);
184189

185-
if($this->results[$address] == 1)
186-
{
190+
if ($this->results[$address] == 1) {
187191
$loopStop = 1;
188192
}
189193
$smtp->noop();
@@ -201,12 +205,11 @@ public function __construct($emails = array(), $sender = '', $options = array())
201205
}
202206

203207
} else {
204-
205208
// 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');
208210
}
209-
211+
} else {
212+
$this->setDomainResults($users, $dom, 0,'no connection ');
210213
}
211214

212215
if ($options['domainMoreInfo']) {
@@ -279,15 +282,19 @@ public function setSender($email)
279282
* @param array $users Array of users (usernames)
280283
* @param Domain $domain The domain
281284
* @param int $val Value to set
285+
* @param String $info Optional , can be used to give additional information about the result
282286
*/
283-
private function setDomainResults($users, Domain $domain, $val)
287+
private function setDomainResults($users, Domain $domain, $val, $info='')
284288
{
285289
if (!is_array($users)) {
286290
$users = (array)$users;
287291
}
288292

289293
foreach ($users as $user) {
290-
$this->results[$user . '@' . $domain->getDomain()] = $val;
294+
$this->results[$user . '@' . $domain->getDomain()] = [
295+
'result' => $val,
296+
'info' => $info
297+
];
291298
}
292299
}
293300
}

0 commit comments

Comments
 (0)