在阅读了大量解决方案的测试后,我仍然收到此错误。
我的参数.yml
parameters:
database_host: 127.0.0.1
database_port: null
database_name: symfony
database_user: root
database_password: null
secret: holamundo
mailer_transport: smtp
mailer_encryption: ssl
mailer_port: 465
mailer_auth_mode: login
mailer_host: smtp.gmail.com
mailer_user: justexample@gmail.com
mailer_password: nottherealone
我的config.yml
# Swiftmailer Configuration
swiftmailer:
transport: %mailer_transport%
encryption: %mailer_encryption%
auth_mode: %mailer_auth_mode%
host: %mailer_host%
port: %mailer_port%
username: %mailer_user%
password: %mailer_password%
spool: { type: memory }
测试swiftmailer trough命令行......
php bin/console swiftmailer:email:send
我收到此错误:
[app] Exception occurred while flushing email queue: Connection could not be established with host smtp.gmail.com [ #0] [] []
如果我ping'smtp.gmail.com',我会收到回复。
我在localhost:8000上运行symfony,很多人都说要将mailer_host更改为类似...
mailer_host: 127.0.0.1
但是我在不同的端口上运行它,所以如果我把它放在
mailer_host: 127.0.0.1:8000
甚至是
mailer_host: 127.0.0.1
mailer_port: 8000
我明白了:
ERROR [app] Exception occurred while flushing email queue: Expected response code 220 but got code "", with message "" [] []
谢谢!
答案 0 :(得分:0)
如果你想使用gmail进行测试,你的parameter.yml文件应该如下所示
mailer_transport: gmail
mailer_host: null
mailer_user: email_address
mailer_password: 'password'
在Controller中使用它
$messenger = \Swift_Message::newInstance();
$messenger->setFrom(array("email_address" => "The name you want to be displayed "));
$messenger->setTo(array($email1, $email2, ...));
$messenger->setCc(array($email1, $email2, ...));
$messenger->setSubject($subject);
$messenger->setBody($body, 'text/html');
$this->mailer->send($messenger);
有关在symfony中发送电子邮件的详细信息,请查看此处 https://symfony.com/doc/current/email.html
答案 1 :(得分:0)
尝试停用防病毒软件。 Avast阻止了我的发送电子邮件操作,而Symfony 3给了我同样的错误消息! 希望对您有帮助