【问题标题】:Symfony SwiftMailer - Expected response code 220 but got code "", with message ""Symfony SwiftMailer - 预期响应代码 220,但得到代码“”,带有消息“”
【发布时间】:2016-05-28 04:48:01
【问题描述】:

我知道这个问题已经有很多答案,例如this,但似乎没有一个解决方案适合我。

我正在尝试从我的 Google Apps 域发送电子邮件。大部分时间都在发送电子邮件,但有时会引发此异常并且电子邮件不会发送。

Uncaught PHP Exception Swift_TransportException: "Expected response code 220 but got code "", with message """ at C:\HostingSpaces\abc\domain.com\wwwroot\vendor\swiftmailer\swiftmailer\lib\classes\Swift\Transport\AbstractSmtpTransport.php line 383 {"exception":"[object] (Swift_TransportException(code: 0): Expected response code 220 but got code \"\", with message \"\" at C:\\HostingSpaces\\abc\\domain.com\\wwwroot\\vendor\\swiftmailer\\swiftmailer\\lib\\classes\\Swift\\Transport\\AbstractSmtpTransport.php:383)"} []

是的,我使用 SSL,是的,我已授予对安全性较低的应用程序的访问权限,是的,我使用端口 465。我已启用假脱机,这样应用程序就不会因为异常未被捕获而崩溃。

我的 config.yml 在下面

swiftmailer:
    transport:  smtp
    host:       smtp.gmail.com
    username:   no-reply@googledomain.com
    password:   password
    port:       465
    encryption: ssl
    spool: { type: memory }

我的电子邮件课程在下面

public function send_new_order_email($entity) {
    try{
        $message = $this->getEmailObj("toaddress@gmail.com");
        $message->setBody(
                $this->renderView(
                    'APIBundle:Emails:ops_neworder.html.twig',
                    array('entity' => $entity)
                ),
                'text/html'
            )->setSubject('New Order : '.$entity->getId());

        $this->container->get('mailer')->send($message);
    }
    catch(Exception $e){}
}

private function getEmailObj($email){
    $message = \Swift_Message::newInstance()
            ->setFrom('no-reply@googledomain.com')
            ->setTo($email);
    return $message;
}

您对这项工作有什么建议吗?

【问题讨论】:

    标签: php symfony smtp gmail swiftmailer


    【解决方案1】:

    在带有 Swiftmailer 的 Symfony 中有一个专门的 Gmail 配置,它处理电子邮件通信而忘记了其余的配置。这在很多场合都对我有用:

    swiftmailer:
        transport: gmail
        username:  your_gmail_username
        password:  your_gmail_password
    

    我希望这对你有意义

    You have more information here

    【讨论】:

      猜你喜欢
      • 2017-08-03
      • 2011-06-23
      • 2015-12-18
      • 2017-08-29
      • 1970-01-01
      • 2015-09-16
      • 2018-05-03
      • 2017-01-15
      相关资源
      最近更新 更多