无法与主机smtp.gmail.com symfony 4建立连接

时间:2018-02-17 18:48:26

标签: symfony smtp gmail swiftmailer

当我尝试使用symfony 4在dev env中发送电子邮件时,我有

  

刷新电子邮件队列时发生异常:无法与主机smtp.gmail.com建立连接[#0]

我的.env是 MAILER_URL = Gmail的:// XXXXXX:XXXXXX @本地

我已经尝试过了 MAILER_URL = Gmail的:// XXXXX:XXXXX @本地加密= TLS

但同样的错误。

我的功能

    public function sendEmail( \Swift_Mailer $mailer)
{
    $message = (new \Swift_Message('Hello Email'))
        ->setFrom('send@example.com')
        ->setTo('recipient@example.com')
        ->setBody(
            $this->renderView(
            // templates/emails/registration.html.twig
                'emails/registration.html.twig',
                array('name' => 'romain')
            ),
            'text/html'
        )
        /*
         * If you also want to include a plaintext version of the message
        ->addPart(
            $this->renderView(
                'emails/registration.txt.twig',
                array('name' => $name)
            ),
            'text/plain'
        )
        */
    ;

    $mailer->send($message);

    return new Response('<body>mail ok</body>');
}

我看到邮件是通过调试栏正确生成的,它只是gmail的smtp无效。

有人可以帮忙吗?

感谢。

0 个答案:

没有答案
相关问题