【发布时间】:2018-07-23 16:25:26
【问题描述】:
我正在开发一个 Symfony 4 应用程序,使用 Swift_Mailer 发送电子邮件。
由于在我的情况下不可能使用 SMTP(不要问为什么……)我必须使用类似 sendmail 的东西。
默认情况下,Swift Mailer 的配置是在 Symfony 的 .env 文件中以 URL 表示法在名为 MAILER_URL 的选项中完成的。默认值为“null://localhost”,根本不发送邮件。
我所能找到的所有值都是 Gmail 或一般 SMTP 的示例,如 Symfony docs 以及 Composer 生成的示例 .env 中所述。
.env 的默认内容:
# …
###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=null://localhost
###< symfony/swiftmailer-bundle ###
# …
我不知道什么,因此我的问题是:
我需要做什么才能让sendmail 使用它?
我已经尝试过类似的方法:
MAILER_URL=sendmail://localhost
和
MAILER_URL=sendmail://my-domain.com
但到目前为止没有成功。
使用控制台命令时
bin/console swiftmailer:email:send
我什至收到“[OK] 1 封电子邮件已成功发送”。结果,但实际上没有发送电子邮件。
(……顺便说一句,没有假脱机。bin/console swiftmailer:spool:send 返回“发送了 0 封电子邮件”。)
邮件传递似乎被中断了,因为邮件不会到达我的邮件帐户,而且我的垃圾邮件是空的。
另一方面,直接调用sendmail 命令确实有效。 (虽然我的测试邮件到达了我的垃圾邮件,但仍然:邮件已发送。)
同样,我必须如何在 Symfony 4 的 .env 中为 Swift_Mailer 配置 MAILER_URL 才能使用 sendmail?
有可能吗?
【问题讨论】:
-
我在 symfony 2 上找到了this。尝试适应 .env 变量!
标签: php email sendmail swiftmailer symfony4