邮件symfony 4无法正常工作 [英] mailer symfony 4 not working

查看:108
本文介绍了邮件symfony 4无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用symfony 4开始了一个项目,但是邮件程序不起作用,但这应该很容易. 在您问之前,如果我复制了我的代码中的登录名和密码,便能够登录我的邮件帐户,我也尝试了一个netcourrier邮件帐户,并且2种方式的身份验证均未激活,并且我允许使用的安全性较低的应用程序访问邮件帐户. 这是我的conf: 在我的.env中:

I started a project using symfony 4 and the mailer doesn't work, however it should be easy. before you ask, if i copy past the login and password from my code i'm able to log into my mail account, also i also tried with a netcourrier mail account, also the 2 way authentification is not active and i allowed less secure app to access the mail account. Here's my conf: in my .env:

MAILER_URL=gmail://*******@gmail.com:********@localhost

在我的控制器中:

public function contact( \Swift_Mailer $mailer){

$message = (new \Swift_Message('Hello Email'))
        ->setFrom('*****@gmail.com')
        ->setTo('*******@gmail.com')
        ->setBody(
            $this->renderView(
                // templates/emails/registration.html.twig
                'email/registration.html.twig',
                array('url' => $url)
            ),
            'text/html'
        );
        $mailer->send($message);
return $this->render(
            'email/index.html.twig');}

我这样做的错误是:

Connection could not be established with host smtp.gmail.com [ #0]

推荐答案

我认为这不是邮递员的问题,而是gmail.我复制了您的步骤以尝试通过gmail的smtp服务器进行连接,但遇到了相同的错误.在.env文件中使用不同的MAILER_URL(不同的smtp服务器)时,所有操作均应按应有的方式进行.

I think this is not an issue with the mailer, but with gmail. I copied your steps to try to connect through the smtp server of gmail, but got the same error. When using a different MAILER_URL (a different smtp-server) in the .env file, everything works like it should.

这篇关于邮件symfony 4无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆