Skip to content
MtrXTools

stream_socket_enable_crypto(): SSL operation failed with code 1

PHP failed to set up TLS on a stream

Seen in PHP streams, PHPMailer, Symfony Mailer, SwiftMailer, file_get_contents

PHP could not complete TLS on a socket, usually for SMTP STARTTLS or HTTPS streams; the OpenSSL message that follows gives the reason.

Common causes

  • "certificate verify failed": PHP has no CA bundle (openssl.cafile) or the server chain is incomplete.
  • Connecting to a mail server by IP or a shared hostname that does not match its certificate.
  • No common TLS version with an old server or old PHP/OpenSSL build.

How to fix it

  1. Read the "OpenSSL Error messages" line after the warning.
  2. Set openssl.cafile in php.ini to a current CA bundle.
  3. Connect using the hostname on the server certificate, such as the provider SMTP hostname.
  4. Update PHP and OpenSSL if the server requires TLS 1.2 or later.
Check the certificate

Got a different message? Paste it into the error explainer.

Related errors

All 32 Languages & runtimes errors