Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMTP Error: Could not connect to SMTP host. STARTTLS command failed Unrecognized command 'STARTTLS' #3021

Closed
abin2011 opened this issue Feb 20, 2024 · 9 comments

Comments

@abin2011
Copy link

  1. PHPMailer Version : 6.9.1
  2. PHP Version: 7.3.33
  3. PHP Code : use examples/smtp.phps
  4. Error Code:

2024-02-20 07:57:32 Connection: opening to webmail.mydomain.com:587, timeout=300, options=array ( 'ssl' => array ( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ),)
2024-02-20 07:57:32 Connection: opened
2024-02-20 07:57:32 SMTP INBOUND: "220 webmail.mydomain.com Microsoft ESMTP MAIL Service ready at Tue, 20 Feb 2024 15:57:31 +0800"
2024-02-20 07:57:32 SERVER -> CLIENT: 220 webmail.mydomain.com Microsoft ESMTP MAIL Service ready at Tue, 20 Feb 2024 15:57:31 +0800
2024-02-20 07:57:32 CLIENT -> SERVER: EHLO client.macaupage.com
2024-02-20 07:57:32 SMTP INBOUND: "250-webmail.mydomain.com Hello [mydomain.com IP]"
2024-02-20 07:57:32 SMTP INBOUND: "250-SIZE 37748736"
2024-02-20 07:57:32 SMTP INBOUND: "250-PIPELINING"
2024-02-20 07:57:32 SMTP INBOUND: "250-DSN"
2024-02-20 07:57:32 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2024-02-20 07:57:32 SMTP INBOUND: "250-AUTH GSSAPI NTLM"
2024-02-20 07:57:32 SMTP INBOUND: "250-8BITMIME"
2024-02-20 07:57:32 SMTP INBOUND: "250-BINARYMIME"
2024-02-20 07:57:32 SMTP INBOUND: "250-CHUNKING"
2024-02-20 07:57:32 SMTP INBOUND: "250 SMTPUTF8"
2024-02-20 07:57:32 SERVER -> CLIENT: 250-webmail.mydomain.com Hello [mydomain.com IP]250-SIZE 37748736250-PIPELINING250-DSN250-ENHANCEDSTATUSCODES250-AUTH GSSAPI NTLM250-8BITMIME250-BINARYMIME250-CHUNKING250 SMTPUTF8
2024-02-20 07:57:32 CLIENT -> SERVER: STARTTLS
2024-02-20 07:57:37 SMTP INBOUND: "500 5.3.3 Unrecognized command 'STARTTLS'"
2024-02-20 07:57:37 SERVER -> CLIENT: 500 5.3.3 Unrecognized command 'STARTTLS'
2024-02-20 07:57:37 SMTP ERROR: STARTTLS command failed: 500 5.3.3 Unrecognized command 'STARTTLS'
SMTP Error: Could not connect to SMTP host. STARTTLS command failed Unrecognized command 'STARTTLS'
2024-02-20 07:57:37 CLIENT -> SERVER: QUIT
2024-02-20 07:57:37 SMTP INBOUND: "221 2.0.0 Service closing transmission channel"
2024-02-20 07:57:37 SERVER -> CLIENT: 221 2.0.0 Service closing transmission channel
2024-02-20 07:57:37 Connection: closed
SMTP Error: Could not connect to SMTP host. STARTTLS command failed Unrecognized command 'STARTTLS'
Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host. STARTTLS command failed Unrecognized command 'STARTTLS'

@XL-2000
Copy link

XL-2000 commented Feb 20, 2024

This is NOT a PHPMailer problem, it is related to either how you have configured SSL and/or TLS.
It may be related to the certificates you are using, and/or the config on the SMTP server.
Also, please note that you are providing the LEAST secure SSL option, which is not recommended.
Please, when done testing, revert to
'verify_peer' => true, 'verify_peer_name' => true, 'allow_self_signed' => false

@XL-2000
Copy link

XL-2000 commented Feb 20, 2024

And please, from the README file:

and before you ask a question about "SMTP Error: Could not connect to SMTP host.", read the troubleshooting guide (https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting).

@Synchro
Copy link
Member

Synchro commented Feb 20, 2024

You have two problems here. Your mail server is misconfigured – while offering a submission service on port 587, it lacks support for STARTTLS, which is an RFC contravention. The second issue is that it supports only GSSAPI and NTLM authentication, neither of which PHPMailer supports. They are largely obsolete; very old versions of PHPMailer used to have NTLM support, but it was dropped years ago.

Separately from these issues, this server is insecure because it advertises authentication methods without requiring encryption first, and these authentication schemes are not considered secure over unencrypted channels.

In short, you need a better mail server.

As @XL-2000 said, don't disable certificate validation. Here it's irrelevant because the server doesn't provide certificates anyway, but you shouldn't be doing it anyway.

@Synchro Synchro closed this as completed Feb 20, 2024
@abin2011
Copy link
Author

I started by defaulting to not disabling the certificate, and got the same result:
SMTP Error: Could not connect to SMTP host. STARTTLS command failed Unrecognized command 'STARTTLS'
Change the parameters to this: 'verify_peer' => true, 'verify_peer_name' => true, 'allow_self_signed' => false and the result is the same.

@abin2011
Copy link
Author

The same code could be sent normally before.
But a few days ago, it suddenly stopped working. Because the SMTP for email is provided by the customer, we have no way to set it up. However, the customer reported that using asp.net, the SMTP service can be used to send emails normally.

@Synchro
Copy link
Member

Synchro commented Feb 20, 2024

Yes, that's why I said the ssl settings were irrelevant – you have no encryption, so there is no certificate to verify, so changing verification settings won't make any difference.

If you don't change anything in your script, then the mail server must have changed. It would not surprise me if it's an obsolete server; it's really common for MS servers to be many years out of date, and a patch update can break things.

asp.net is a proprietary Microsoft product and as such provides support for proprietary Microsoft protocols like GSSAPI and NTLM. If you need to maintain compatibility with them, switch to asp.net; you're not going to get support for them here.

@Synchro Synchro reopened this Feb 20, 2024
@abin2011
Copy link
Author

Is it necessary to configure the mail server certificate to deal with this problem?
How should I describe how to fix this smtp service?
So how else can I use the smtp service to send emails?

@Synchro
Copy link
Member

Synchro commented Feb 20, 2024

Yes, you need to ask them to do these things:

  • Enable encryption (STARTTLS on port 587 and SMTPS on port 465)
  • Require encryption before authentication (that they are not doing this already is a bad sign)
  • Enable support for standard LOGIN and/or PLAIN authentication schemes

@Synchro Synchro closed this as completed Feb 20, 2024
@abin2011
Copy link
Author

OK, thank you very much for your answer

Yes, you need to ask them to do these things:

  • Enable encryption (STARTTLS on port 587 and SMTPS on port 465)
  • Require encryption before authentication (that they are not doing this already is a bad sign)
  • Enable support for standard LOGIN and/or PLAIN authentication schemes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants