【问题标题】:how to solve Zend\Mail\Protocol\Exception\RuntimeException如何解决 Zend\Mail\Protocol\Exception\RuntimeException
【发布时间】:2015-06-03 09:18:32
【问题描述】:

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

F:\xampp1\htdocs\ZendFramework\vendor\zendframework\zendframework\library\Zend\Mail\Protocol\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();,那么它会给出错误:

由于目标机器主动拒绝,无法建立连接

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

【问题讨论】:

    标签: php email zend-framework


    【解决方案1】:

    我已经解决了这个问题:

    $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',                                                                 
                                 )
                      );
    

    【讨论】:

      猜你喜欢
      • 2014-09-12
      • 2019-10-14
      • 2013-10-10
      • 1970-01-01
      • 1970-01-01
      • 2014-11-26
      • 2011-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多