I am using MagePal SMTP extension, but on testing through admin portal it is giving error could not open socket in fresh installation without any other extension. Any solution?
You need to try this.
open this file :
arround line no 267.
$this->_socket = @stream_socket_client($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);
comment above line and add this code below that line.
$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 );
I have spend a week to find out a solution for this and finally find out disabling "SMTP Restrictions" via WHM, allowed emails to go through and work as expected. See attached screenshot. Apply Dhiren's solution and then disable "SMTP Restrictions" also make sure you enable “Allow less secure apps” if using google account.
Magento version: 2.3.3
SELINUX BLOCKING If you are getting error message like SMTP -> ERROR: Failed to connect to server: Permission denied (13), Permission denied, and your are hosting on RedHat / Fedora / Centos this is more than likely cause by SELinux preventing PHP or the web server from sending email. . Using the getsebool command we can check if the httpd daemon is allowed to make a connection over the network and send an email:
getsebool httpd_can_sendmail getsebool httpd_can_network_connect
This command will return a boolean on or off. If it’s off, we can turn it on:
sudo setsebool -P httpd_can_sendmail 1 sudo setsebool -P httpd_can_network_connect 1