Skip to content

Commit dc0fbc0

Browse files
added $info to setDomainResults
added descriptions in validation steps
1 parent 58973f6 commit dc0fbc0

File tree

1 file changed

+66
-63
lines changed

1 file changed

+66
-63
lines changed

lib/SmtpValidatorEmail/ValidatorEmail.php

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public function __construct($emails = array(), $sender = '', $options = array())
8888
$emailBag->add((array)$emails);
8989
$domainBag = $this->setEmailsDomains($emailBag);
9090
$this->domains = $domainBag->all();
91-
9291
}
9392

9493
if (!empty($sender)) {
@@ -132,86 +131,85 @@ public function __construct($emails = array(), $sender = '', $options = array())
132131

133132
} catch (ExceptionNoConnection $e) {
134133
// unable to connect to host, so these addresses are invalid?
135-
$this->setDomainResults($users, $dom, 0);
134+
$this->setDomainResults($users, $dom, 0,'unable to connect to host');
136135
}
137136
}
138-
try {
139-
// are we connected?
140-
if ($smtp->isConnect()) {
141137

138+
// are we connected?
139+
if ($smtp->isConnect()) {
142140

143-
sleep($options['delaySleep'][$i]);
144141

145-
// say helo, and continue if we can talk
146-
if ($smtp->helo()) {
142+
sleep($options['delaySleep'][$i]);
147143

148-
// try issuing MAIL FROM
149-
if (!($smtp->mail($this->fromUser . '@' . $this->fromDomain))) {
150-
// MAIL FROM not accepted, we can't talk
151-
$this->setDomainResults($users, $dom, $options['noCommIsValid']);
152-
}
144+
// say helo, and continue if we can talk
145+
if ($smtp->helo()) {
153146

154-
/**
155-
* if we're still connected, proceed (cause we might get
156-
* disconnected, or banned, or greylisted temporarily etc.)
157-
* see mail() for more
158-
*/
159-
if ($smtp->isConnect()) {
147+
// try issuing MAIL FROM
148+
if (!($smtp->mail($this->fromUser . '@' . $this->fromDomain))) {
149+
// MAIL FROM not accepted, we can't talk
150+
$this->setDomainResults($users, $dom, $options['noCommIsValid'],'MAIL FROM not accepted');
151+
}
152+
153+
/**
154+
* if we're still connected, proceed (cause we might get
155+
* disconnected, or banned, or greylisted temporarily etc.)
156+
* see mail() for more
157+
*/
158+
if ( $smtp->isConnect()) {
159+
160+
$smtp->noop();
161+
162+
// Do a catch-all test for the domain always.
163+
// This increases checking time for a domain slightly,
164+
// but doesn't confuse users.
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+
}
160170

161-
$smtp->noop();
162171

163-
// Do a catch-all test for the domain always.
164-
// This increases checking time for a domain slightly,
165-
// but doesn't confuse users.
166-
try{
167-
$isCatchallDomain = $smtp->acceptsAnyRecipient($dom);
168-
}catch (\Exception $e) {
169-
$this->setDomainResults($users, $dom, $options['catchAllIsValid']);
172+
// if a catchall domain is detected, and we consider
173+
// accounts on such domains as invalid, mark all the
174+
// users as invalid and move on
175+
if ($isCatchallDomain) {
176+
if (!$options['catchAllIsValid']) {
177+
$this->setDomainResults($users, $dom, $options['catchAllIsValid'],'catch all detected');
178+
continue;
170179
}
180+
}
171181

182+
// if we're still connected, try issuing rcpts
183+
if ($smtp->isConnect()) {
184+
$smtp->noop();
185+
// rcpt to for each user
186+
foreach ($users as $user) {
187+
$address = $user . '@' . $dom->getDomain();
188+
$this->results[$address] = $smtp->rcpt($address);
172189

173-
// if a catchall domain is detected, and we consider
174-
// accounts on such domains as invalid, mark all the
175-
// users as invalid and move on
176-
if ($isCatchallDomain) {
177-
if (!$options['catchAllIsValid']) {
178-
$this->setDomainResults($users, $dom, $options['catchAllIsValid']);
179-
continue;
190+
if ($this->results[$address] == 1) {
191+
$loopStop = 1;
180192
}
181-
}
182-
183-
// if we're still connected, try issuing rcpts
184-
if ($smtp->isConnect()) {
185193
$smtp->noop();
186-
// rcpt to for each user
187-
foreach ($users as $user) {
188-
$address = $user . '@' . $dom->getDomain();
189-
$this->results[$address] = $smtp->rcpt($address);
190-
191-
if ($this->results[$address] == 1) {
192-
$loopStop = 1;
193-
}
194-
$smtp->noop();
195-
}
196-
}
197-
198-
// saying buh-bye if we're still connected, cause we're done here
199-
if ($smtp->isConnect()) {
200-
// issue a rset for all the things we just made the MTA do
201-
$smtp->rset();
202-
// kiss it goodbye
203-
$smtp->disconnect();
204194
}
195+
}
205196

197+
// saying buh-bye if we're still connected, cause we're done here
198+
if ($smtp->isConnect()) {
199+
// issue a rset for all the things we just made the MTA do
200+
$smtp->rset();
201+
// kiss it goodbye
202+
$smtp->disconnect();
206203
}
207204

208-
} else {
209-
// we didn't get a good response to helo and should be disconnected already
210-
$this->setDomainResults($users, $dom, $options['noCommIsValid']);
211205
}
206+
207+
} else {
208+
// we didn't get a good response to helo and should be disconnected already
209+
$this->setDomainResults($users, $dom, $options['noCommIsValid'],'bad response on helo');
212210
}
213-
} catch (\Exception $e) {
214-
$this->setDomainResults($users, $dom, 0);
211+
} else {
212+
$this->setDomainResults($users, $dom, 0,'no connection ');
215213
}
216214

217215
if ($options['domainMoreInfo']) {
@@ -284,15 +282,20 @@ public function setSender($email)
284282
* @param array $users Array of users (usernames)
285283
* @param Domain $domain The domain
286284
* @param int $val Value to set
285+
* @param String $info Optional , can be used to give additional information about the result
287286
*/
288-
private function setDomainResults($users, Domain $domain, $val)
287+
private function setDomainResults($users, Domain $domain, $val, $info='')
289288
{
289+
echo 'setDomain Called';
290290
if (!is_array($users)) {
291291
$users = (array)$users;
292292
}
293293

294294
foreach ($users as $user) {
295-
$this->results[$user . '@' . $domain->getDomain()] = $val;
295+
$this->results[$user . '@' . $domain->getDomain()] = [
296+
'result' => $val,
297+
'info' => $info
298+
];
296299
}
297300
}
298301
}

0 commit comments

Comments
 (0)