问题描述
我正在使用 Symfony 4
和 FOSUserBundle
在本地服务器上工作.当新用户注册时,我无法收到确认电子邮件.
I´m working in a localhost server with Symfony 4
and FOSUserBundle
. I can't manage to receive the email confirmation when a new user is registered.
我尝试了以下帖子,但在我的情况下不起作用:Symfony 4 SwiftMailer Gmail:电子邮件未发送
I have tried the following post but it´s not working in my case:Symfony 4 SwiftMailer Gmail : Email not sent
我尝试将 SwiftMailer 配置为使用 gmail smtp server
和 mailtrap smtp server
发送,但没有成功.我也检查了 dev.log
并没有发现错误.
I have tried to configure SwiftMailer to send using gmail smtp server
and mailtrap smtp server
without success. Also I have checked dev.log
and no errors are found.
我不确定哪个是配置 Swift Mailer 的正确文件(.env 或 packages/dev/swiftmailer.yaml).现在的配置如下:
I´m not sure which is the right file to configure Swift Mailer (.env or packages/dev/swiftmailer.yaml). Right now the configuration is the following:
.env 文件:
MAILER_URL=gmail://***@gmail.com:***@localhost
swiftmailer.yaml:
swiftmailer.yaml:
swiftmailer:
transport: gmail
username: ***@gmail.com
password: ***
host: localhost
port: 465
encryption: ssl
auth-mode: login
spool: { type: 'memory' }
stream_options:
ssl:
allow_self_signed: true
verify_peer: false
verify_peer_name: false
有什么想法吗?使用 gmail 作为 smtp 服务器不是强制性的.
Any ideas? It´s not mandatory to use gmail as the smtp server.
先谢谢了.
解决方案:
问题出在/config/test/fos_user.yaml 文件中:
The problem was in the /config/test/fos_user.yaml file:
我改变了:
service:
mailer: 'fos_user.mailer.noop'
致:
service:
mailer: 'fos_user.mailer.default'
文档:http://symfony.com/doc/master/bundles/FOSUserBundle/emails.html
此外,为了工作,我接受了来自 Gmail 帐户设置的安全性较低的连接.
Also I have accepted less secure connections from the gmail account setting in order to work.
推荐答案
我在使用 Symfony 4 时遇到了同样的问题.我的包版本swiftmailer/swiftmailer v6.1.0symfony/swiftmailer-bundle v3.2.2当我使用配置时:迅捷邮递员:url: '%env(MAILER_URL)%'线轴:{ 类型:'内存' }
I had the same problem with Symfony 4. My packages versionswiftmailer/swiftmailer v6.1.0symfony/swiftmailer-bundle v3.2.2When I used configuration: swiftmailer: url: '%env(MAILER_URL)%' spool: { type: 'memory' }
电子邮件没有发送,也没有发生异常.然后我将设置更改为:
The emails were not send and no exception occurred.Then I change the settings into:
swiftmailer:url: '%env(MAILER_URL)%'线轴:类型:'文件'路径:'%kernel.cache_dir%/swiftmailer/spool'
并尝试命令:
php bin/console swiftmailer:spool:send --env=dev -vvv
我看到了错误:
[Swift_SwiftException]
未找到 IDN 编码器(安装 intl 扩展或 true/punycode 包所以我通过以下方式安装了 true/punycode 包:
[Swift_SwiftException]
So I installed true/punycode package via:
No IDN encoder found (install the intl extension or the true/punycode package
composer req true/punycode
现在电子邮件发送也很好,带有假脱机内存.
and now emails are sending fine also with spool memory.
这篇关于Symfony 4 Swift Mailer 不发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!