【问题标题】:Symfony swiftmailer in production environment生产环境中的 Symfony swiftmailer
【发布时间】:2015-03-28 20:11:43
【问题描述】:

我在 Symfony2 中使用 Swiftmailer 发送邮件时遇到问题。 让我解释一下:当我用app_dev.php访问我的网站时,我可以发送消息,没有问题(还有,当我在app.php中写$kernel = new AppKernel('prod', true);时)。

所以,我不明白为什么这适用于开发而不是生产。

这是我的配置文件:

parameters.yml:

mailer_transport: smtp
mailer_host: ****.ovh.net
mailer_username: postmaster@mywebsite.com
mailer_password: ****
mailer_port: ****

config.yml:

swiftmailer:
transport: "%mailer_transport%"
host:      "%mailer_host%"
username:  "%mailer_username%"
password:  "%mailer_password%"
port:      "%mailer_port%"
spool:     { type: memory }

这是php代码,但我认为它没有问题,因为正如我所说,在开发模式下没有问题。

$message = \Swift_Message::newInstance() -> setSubject('Test')
         -> setFrom('postmaster@mywebsite.com')
         -> setTo($user -> getMail())
         -> setBody('Test');
$this -> get('mailer') -> send($message);

如果您知道问题出在哪里,非常感谢。

【问题讨论】:

  • 你能看看你的 prod.log 看看有没有错误吗?我读了你的问题,有点困惑。你写道:“所以,我不明白为什么这在 prod 中有效,而不在 dev 中有效。”标题说它在产品中不起作用。
  • 很抱歉这是一个错误,我想说“我不明白为什么它在 dev 中有效,而不在 prod 中有效”。所以,这是我尝试发送邮件时的日志:[2015-03-29 11:22:44] app.ERROR: Exception occurred while flushing email queue: Connection could not be established with host smtp.mywebsite.com [php_network_getaddresses: getaddrinfo failed: Name or service not known #0] [] [] 它说,它无法连接到 smtp,但在 dev 中,它可以,这很奇怪......
  • 我建议手动删除 prod 缓存目录并重新安装和转储资产。
  • 有效!非常非常感谢你!我想我忘了清空 prod 缓存,所以 symfony 不知道我对 swiftmailer 的新配置。现在,我觉得我很愚蠢^^。谢谢你:)
  • 既然有效,你能检查一下我添加的答案吗?你不是唯一发生这种情况的人:)

标签: php email symfony production-environment swiftmailer


【解决方案1】:

如果某些东西在 dev 中有效,但在 prod 中无效,请尝试手动删除 prod 缓存目录并再次重新安装和转储资产。查看文档中的 checklist

【讨论】:

    猜你喜欢
    • 2016-04-08
    • 1970-01-01
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-28
    • 2014-11-11
    相关资源
    最近更新 更多