zytzagoo / smtp-validate-email

A PHP library for performing email addresses validation via SMTP
GNU General Public License v3.0
437 stars 155 forks source link

fatal error when validating a specific domain #68

Closed Thanatermesis closed 3 years ago

Thanatermesis commented 3 years ago

If you try to validate with the domain xxx@mailo.com , it shows this fatal error output:

PHP Fatal error: Uncaught SMTPValidateEmail\Exceptions\NoMailFrom: Need MAIL FROM before RCPT TO in /.../composer/vendor/zytzagoo/smtp-validate-email/src/Validator.php:613 Stack trace:

0 /.../composer/vendor/zytzagoo/smtp-validate-email/src/Validator.php(344): SMTPValidateEmail\Validator->rcpt('xxx@mailo....')

zytzagoo commented 3 years ago

Which version/commit are you using exactly? (line numbers seem to be off a bit). And which exact calling code triggers this? Can you create a minimal repro code/case that reliably triggers this state?

Thanatermesis commented 3 years ago

im using a version that i have installed with composer like 1 week ago (how I should update it? i never used composer before)

to reproduce it, is with a simple validation code using the domain mailo.com, like:

$validator = new SmtpEmailValidator("xxx@mailo.com", "noreply@mydomain.com"); $validation = $validator->validate();

Thanatermesis commented 3 years ago

Another domain that shows to have the same issue: [hidden-user]@net-c.com

Thanatermesis commented 3 years ago

also [hidden-user]@lavache.com

zytzagoo commented 3 years ago

Turn on debug if you did not already, and observe/dump the debug output.

Use an actual address as FROM address (or at least not something like noreply which is easily refused). When checking an address like literally xxx@mailo.com you will probably get disconnected/aborted pretty quickly since server knows you are probing etc.

Dont know about other examples, but probably more/less same reasons. It's mostly about reputation of the IP you are connecting from + also port / protocol / auth etc.

Thanatermesis commented 3 years ago

Hello,

I just did a new test, to see if I can obtain some debug, but apparently, there are no results at all, PHP results in a fatal error and nothing is printed. As the other points you say:

Remember that the issue is about having a fatal error in php, nothing is printed and nothing can be cathed, the entire tool im using with smtp-validate-email breaks and cannot continue (if it will return a simple "not valid" result everything will be easier), looks like the FROM value is removed from somwhere in the script process or similar :thinking:

Can you confirm that you can test against those addresses and you obtain (any) result instead of having a fatal error ?

zytzagoo commented 3 years ago

Test file:

<?php declare(strict_types=1);

require 'vendor/autoload.php';

use SMTPValidateEmail\Validator as SmtpEmailValidator;

$validator = new SmtpEmailValidator('xxx@mailo.com', 'noreply@mydomain.com');
$validator->debug = true;
$validator->setConnectTimeout(1);
$smtpResults = $validator->validate();

var_dump($validator->getLog());

Results/output:


[2021-04-20T15:06:29.279959+0000] MX records (mailo.com): Array
(
    [mx.mailo.com] => 10
    [mailo.com] => 0
)

[2021-04-20T15:06:29.280159+0000] Connecting to mx.mailo.com:25
[2021-04-20T15:06:29.373697+0000] Connected to mx.mailo.com:25 successfully
[2021-04-20T15:06:36.780638+0000] <<<recv: 220 b-5.in.mailobj.net ESMTP Server ready

[2021-04-20T15:06:36.784926+0000] send>>>: EHLO mydomain.com
[2021-04-20T15:06:36.830351+0000] <<<recv: 250-b-5.in.mailobj.net welcome

[2021-04-20T15:06:36.830426+0000] <<<recv: 250-PIPELINING

[2021-04-20T15:06:36.831519+0000] <<<recv: 250-VRFY

[2021-04-20T15:06:36.831565+0000] <<<recv: 250-STARTTLS

[2021-04-20T15:06:36.831577+0000] <<<recv: 250-SIZE 73400320

[2021-04-20T15:06:36.831585+0000] <<<recv: 250 HELP

[2021-04-20T15:06:36.831603+0000] send>>>: MAIL FROM:<noreply@mydomain.com>
[2021-04-20T15:06:36.867505+0000] <<<recv: 250 sender ok

[2021-04-20T15:06:36.867624+0000] send>>>: NOOP
[2021-04-20T15:06:36.905214+0000] <<<recv: 250 Ok

[2021-04-20T15:06:36.906505+0000] send>>>: RCPT TO:<xxx@mailo.com>
[2021-04-20T15:06:36.933062+0000] <<<recv: 
[2021-04-20T15:06:36.935567+0000] No response in expect(): No response in recv
[2021-04-20T15:06:36.935617+0000] Closing socket to mx.mailo.com:25PHP Fatal error:  Uncaught SMTPValidateEmail\Exceptions\NoConnection: No connection in ...src/Validator.php:1017
Stack trace:
#0 ...src/Validator.php(843): SMTPValidateEmail\Validator->throwIfNotConnected()
#1 ...src/Validator.php(762): SMTPValidateEmail\Validator->send('RSET')
#2 ...src/Validator.php(467): SMTPValidateEmail\Validator->rset()
#3 ...src/Validator.php(399): SMTPValidateEmail\Validator->attemptMailCommands('mailo.com', Array)
#4 ...src/Validator.php(334): SMTPValidateEmail\Validator->performSmtpDance('mailo.com', Array)
#5 ...src/Validator.php(308): SMTPValidateEmail\Validator->loop()
#6 ...test-issue-68.php(10): SMTPValidateEmail\Validator->validate()
#7 {main}
  thrown in ...src/Validator.php on line 1017

Fatal error: Uncaught SMTPValidateEmail\Exceptions\NoConnection: No connection in ...src/Validator.php:1017
Stack trace:
#0 ...src/Validator.php(843): SMTPValidateEmail\Validator->throwIfNotConnected()
#1 ...src/Validator.php(762): SMTPValidateEmail\Validator->send('RSET')
#2 ...src/Validator.php(467): SMTPValidateEmail\Validator->rset()
#3 ...src/Validator.php(399): SMTPValidateEmail\Validator->attemptMailCommands('mailo.com', Array)
#4 ...src/Validator.php(334): SMTPValidateEmail\Validator->performSmtpDance('mailo.com', Array)
#5 ...src/Validator.php(308): SMTPValidateEmail\Validator->loop()
#6 ...test-issue-68.php(10): SMTPValidateEmail\Validator->validate()
#7 {main}
  thrown in ...src/Validator.php on line 1017

Note that the server forcibly closes the connection as soon as it (probably) sees a non-existing RCPT TO, or whatever... The possibilities why they close connection are endless.

This library cannot (and will not) cater to automatically handling any possible weird combination of things email servers in the wild on the entire internet do (and they legit do it in order to deter spammers first and foremost).

That (writing code to handle special/custom cases/servers/addresses etc) is the job of the code that is using/wrapping/calling this library. And that is something a developer needs to write on his own, because only he knows his exact needs/requirements.

For completeness, you can wrap the entire test code/thing above (along with debug log printing) inside a try/catch statement, and you will not get a "fatal error" then... But, again, this also has nothing to do with the library itself, it's a general php "question"...

Thanatermesis commented 3 years ago

Ok, I was able to wrap the code to return an "unknown" result state, this can do the work