ZF2发送邮件总是出错[无法打开套接字]

时间:2015-07-15 03:37:08

标签: php sockets email zend-framework2

我正在使用Zend Mail发送来自Zimbra的电子邮件。

        $message = new \Zend\Mail\Message();
        $message->setBody("test");
        $message->setFrom("febri.damatraseta@mydomainzimbra.com");
        $message->setSubject("Trying to send an email");
        $message->addTo("febryfairuz@gmail.com");

        $smtpOptions = new \Zend\Mail\Transport\SmtpOptions();
        $smtpOptions->setHost("192.123.456.789:01")
                    ->setConnectionClass('login')
                    ->setName('192.123.456.789:01')
                    ->setConnectionConfig(array(
                        'username'  => 'febri.damatraseta@mydomainzimbra.com',
                        'password'  => '123abc',
                        'ssl'       => 'tls'
                    ));
        $transport = new \Zend\Mail\Transport\Smtp($smtpOptions);
        $transport->send($message);

我收到此错误:

Could not open socket

我安装了OpenSSL。 你能救我吗?

1 个答案:

答案 0 :(得分:0)

几周前我遇到了同样的问题,这是正确的用法:

// Setup SMTP transport using LOGIN authentication
        $transport = new SmtpTransport ();
        $options = new SmtpOptions ( array (
                'name' => 'whatever.com',
                'host' => 'smtp',
                'connection_class' => 'plain',
                'port' => '587', // Notice port change for TLS is 587
                'connection_config' => array (
                        'username' => '',
                        'password' => '',
                        'ssl' => 'tls' 
                ) 
        ) );
        $transport->setOptions ( $options );
        $transport->send ( $message );