Magento 2 SMTP could not open socket
The file to edit:
Find below line:
$this->_socket = @stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);
replace it with 1 :
$stream_context = stream_context_create(array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) )); $this->_socket = stream_socket_client( $remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION, STREAM_CLIENT_CONNECT, $stream_context );
In some cases, the server itself also blocks SMTP ports.
If you are using WHM/Cpanel, you may also need to disable “SMTP Restrictions” on WHM and in case of using such as Gmail, select “Allow less secure apps” in settings 2.Reference: