Symfony SwiftMailer - 预期的响应代码220,但代码为“”,消息为“”

时间:2016-02-16 18:35:55

标签: php symfony smtp gmail swiftmailer

我知道这个问题在SO上有很多像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;
}

你有什么建议让这项工作吗?

1 个答案:

答案 0 :(得分:0)

在Symfony中,Swiftmailer是一个专门用于Gmail的配置,它处理电子邮件通信,忘记了其余的配置。这对我来说很多次:

swiftmailer:
    transport: gmail
    username:  your_gmail_username
    password:  your_gmail_password

我希望这对你有意义

You have more information here

相关问题