Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "could not open socket in Zend Mail (Zend Framework 2)

Tags:

php

Please help me fix problem on Mac OS, when I type on my windows, It works. I try on my mac, it shows "could not open socket". Everybody could help me.

public function indexAction(){
    $mail = new Mail\Message;
                $mail->setFrom('[email protected]','Flyoverfly Training');
                $mail->addTo('[email protected]','maithanh');
                $mail->setSubject('Xác nhận việc phục hồi mật khẩu');
                $mail->setBody('maithanh');

                $transport = new SmtpTransport;
                $option = new SmtpOptions(array(
                    'name' => 'smtp.gmail.com',
                    'host' => 'smtp.gmail.com',
                    'port' => 465,
                    'connection_class' => 'login',
                    'connection_config' => array(
                        'username' => '[email protected]',
                        'password' => 'mypass',
                        'ssl' => 'ssl'
                    )
                ));
                $transport->setOptions($option);
                $transport->send($mail);
    return new ViewModel;
}
like image 711
ThanhAkira Avatar asked Feb 10 '15 14:02

ThanhAkira


1 Answers

May be a firewall issue. However I'm pretty sure php-openssl doesn't installed/enabled on your OS. Under the hood Zend will call stream_socket_client() in order to connect to remote server. As sending email through gmail requires security layer (SSL/TLS), stream_socket_client() will require open ssl support (ssl://). So you must have ssl support on OS, check:


enter image description here Or getting the list of supported socket transports:

enter image description here

And here goes some useful links:

  • Roll your own PHP to support OpenSSL instead of Secure Transport (Mac)
  • How to upgrade OpenSSL in OS X?
  • Important note for curl users on OS X Mavericks 10.9
  • fsockopen() (go to hostname option for details)
  • Can't run Composer on my Mac Mountain Lion - openssl extension
  • OpenSSL support in PHP under MAMP
  • OpenSSL Version MacOSX Homebrew
  • Building OpenSSL on your Mac (MacOS X)
  • Zend Mail Abastract Protocol (stream_socket_client under the hoods)
  • stream_socket_client()
  • OpenSSL installation
  • Net Transports
  • stream_get_transports()
like image 191
felipsmartins Avatar answered Nov 07 '22 08:11

felipsmartins