如何解决Zend \ Mail \ Protocol \ Exception \ RuntimeException

时间:2015-05-22 06:39:44

标签: php email zend-framework

我想使用zend框架2发送电子邮件, 我收到此错误:连接尝试失败,因为连接方在一段时间后没有正确响应或建立的连接失败,因为连接的主机无法响应。来自文件:

  

F:\ xampp1 \ htdocs中\ ZendFramework \厂商\ zendframework \ zendframework \库\ Zend的\邮件\协议\ AbstractProtocol.php:209,

我正在使用

$message = new Message();$message->setBody('This is the body');
$message->setFrom('kinjalshah96@gmail.com');$message->addTo( $data['email']);
$message->setSubject('Test subject');
$smtpOptions = new SmtpOptions();
$smtpOptions->setHost('smtp.gmail.com')
    ->setName('smtp.gmail.com')
    ->setConnectionConfig(array(
        'username' => 'kinjalshah96@gmail.com',
        'password' => 'mypassword',
        'ssl' => 'tls',
        'port' => 587,
        'host' => 'localhost:8080',) );
$transport = new Smtp($smtpOptions);
$transport->send($message);

如果我使用$transport = new Smtp();,则会出错:

  

无法建立连接,因为目标计算机主动拒绝它

你能帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:0)

我已使用以下方法解决了该问题:

$smtpOptions->setHost('smtp.gmail.com')                                             
            ->setName('smtp.gmail.com')
            ->setPort(587)
            ->setConnectionClass('login')
            ->setConnectionConfig(array(
                               'username' => 'kinjalshah96@gmail.com',
                               'password' => 'mypassword',
                               'ssl' => 'tls',
                               'host'=>'localhost:8080',                                                                 
                             )
                  );