2

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?

1
  • I post answer, please check. – Dhiren Vasoya Jan 12 '18 at 11:36
9

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 
 );
2
  • yeah it is working now thank you. I have been searching for the solution since last 1 week. . – akshay billore Jan 12 '18 at 11:53
  • 1
    this 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 '18 at 16:44
3

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

enter image description here

1
  • 1
    This Worked for me on Godaddy Hosting! – Usman Yousaf May 16 '20 at 10:27
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.