我正在使用 Symfony 4
和 FOSUserBundle
在localhost服务器上工作 . 注册新用户时,我无法接收电子邮件确认 .
我试过以下帖子,但在我的情况下不起作用:Symfony 4 SwiftMailer Gmail : Email not sent
我试图配置SwiftMailer使用 gmail smtp server
和 mailtrap smtp server
发送没有成功 . 我也检查了 dev.log
,没有发现任何错误 .
我不确定哪个是配置Swift Mailer的正确文件(.env或packages / dev / swiftmailer.yaml) . 现在配置如下:
.env文件:
MAILER_URL=gmail://***@gmail.com:***@localhost
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服务器不是强制性的 .
先谢谢 .
解:
问题出在/config/test/fos_user.yaml文件中:
我变了:
service:
mailer: 'fos_user.mailer.noop'
至:
service:
mailer: 'fos_user.mailer.default'
文件:http://symfony.com/doc/master/bundles/FOSUserBundle/emails.html
此外,我还接受了来自gmail帐户设置的不太安全的连接以便工作 .
2 回答
我遇到了与Symfony 4相同的问题 . 我的软件包版本swiftmailer / swiftmailer v6.1.0 symfony / swiftmailer-bundle v3.2.2当我使用配置时:swiftmailer:url:'%env(MAILER_URL)%'spool:{type:'memory '}
电子邮件未发送,也没有发生异常 . 然后我将设置更改为:
swiftmailer: url: '%env(MAILER_URL)%' spool: type: 'file' path: '%kernel.cache_dir%/swiftmailer/spool'
并试过命令:
php bin/console swiftmailer:spool:send --env=dev -vvv
我看到了错误:
[Swift_SwiftException] No IDN encoder found (install the intl extension or the true/punycode package
所以我通过以下方式安装了true / punycode包:composer req true/punycode
现在电子邮件也随着假脱机内存发送正常 .
Symfony邮件程序的默认行为是立即发送电子邮件消息,但是在配置时,它将“假脱机”电子邮件而不是直接发送它们 .
使用控制台命令单独完成从假脱机发送消息:
@see更多文档here
更新:正如@nek在第一条评论中所说,内存假脱机立即发送邮件(如果没有发生异常) . 只有在使用文件假脱机时才需要spool:send命令 .