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?
-
I post answer, please check.– Dhiren VasoyaJan 12, 2018 at 11:36
4 Answers
You need to try this.
open this file : vendor\magento\zendframework1\library\Zend\Mail\Protocol\Abstract.php
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
);
-
yeah it is working now thank you. I have been searching for the solution since last 1 week. . Jan 12, 2018 at 11:53
-
2this donot work anymore Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol in vendor/magento/zendframework1/library/Zend/Mail/Protocol/Abstract.php on line 281– Kumar A.Oct 5, 2018 at 16:44
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
-
1
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
Thanks to MagePal here is their full documentation
Some hosting providers like Linode are blocking Ports 25, 465, 587. Might be your hosting provider might also have blocked ports.
You can contact your hosting provider to enable SMTP-related ports and It might work.