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. Jan 12, 2018 at 11:36

4 Answers 4


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(
  • yeah it is working now thank you. I have been searching for the solution since last 1 week. . Jan 12, 2018 at 11:53
  • 2
    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, 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

enter image description here

  • 1
    This Worked for me on Godaddy Hosting! May 16, 2020 at 10:27

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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