【问题标题】:Cannot get sendmail to work with Swiftmailer Bundle on Windows无法让 sendmail 在 Windows 上与 Swiftmailer Bundle 一起使用
【发布时间】:2019-02-22 14:40:20
【问题描述】:

我有以下设置/参数:

  • PHP 7.1.26
  • Windows 10 x64 专业版
  • symfony/swiftmailer-bundle 3.5.2
  • symfony/控制台 4.1.11

我想将 swiftmailer-bundle 配置为使用fake sendmail,它安装在

C:\Program Files (x86)\sendmail

虽然我已经在 PHP 中配置了 sendmail_path,但 swiftmailer-bundle 实际上并没有使用这个 PHP 变量。相反,它将 sendmail 可执行文件的路径默认为

/usr/sbin/sendmail -bs

但是,从 3.0.4 版本开始,路径(即完整的命令)应该是可配置的:https://github.com/symfony/swiftmailer-bundle/pull/185

我放了

swiftmailer:
    mailers:
        default:
            transport: sendmail
            command: 'C:\Program Files (x86)\sendmail\sendmail.exe -t'

进入我的app/config/config.yml 并重建缓存。但是,当我想通过发送测试电子邮件时

swiftmailer:email:send

它仍然使用默认命令 - 当然会失败

[Swift_TransportException]
Process could not be started [The system cannot find the specified path.]

我不确定我还能尝试什么。我真的很想在我的本地环境中使用虚假的 sendmail 设置,因为可以将 sendmail 配置为强制将任何电子邮件发送到特定地址(我的地址)进行测试并始终使用特定的 SMTP。

这是debug:config swiftmailer的输出:

swiftmailer:
    default_mailer: default
    mailers:
        default:
            transport: sendmail
            host: 127.0.0.1
            username: null
            password: null
            port: 25
            encryption: null
            command: 'C:\Program Files (x86)\sendmail\sendmail.exe -t'
            url: null
            timeout: 30
            source_ip: null
            local_domain: null
            auth_mode: null
            delivery_addresses: {  }
            logging: false
            delivery_whitelist: {  }

【问题讨论】:

  • 您是否尝试过使用双斜杠:'C:\\Program Files (x86)\\sendmail\\sendmail.exe -t' 而不是 shure 关于空格 :)
  • 在文档glob.com.au/sendmail 中也有一个指向堆栈的链接:) - stackoverflow.com/questions/21337859/sendmail-wamp-php
  • @myxaxa:没有——但我确实在 Swiftmailer 的代码中进行了调试,而配置根本没有到达 Swift_SendmailTransport 类。它仍然使用默认的/usr/sbin/sendmail -bs
  • @myxaxa:Stackoverflow 链接仅涉及 PHP 配置。 Swiftmailer Bundle 不使用 PHP 配置。
  • 抱歉回复晚了。有点奇怪。您确定您的项目中没有其他用于 swiftmailer 的配置吗?请运行以下命令:php bin/console debug:config swiftmailer 并显示输出symfony.com/doc/current/reference/configuration/…

标签: php windows symfony sendmail swiftmailer


【解决方案1】:

更新在 github 上发现一个未解决的问题:https://github.com/symfony/swiftmailer-bundle/issues/244

所以这是一条艰难的道路。但是在你的 swiftmailer.yaml 中试试这个:

swiftmailer:
    default_mailer: default
    mailers:
        default:
            transport: sendmail
            command: '%env(SENDMAIL_COMMAND)%'
            timeout: 20

并在您的 .env 文件中添加一个新的环境变量:

SENDMAIL_COMMAND='C:\Program Files (x86)\sendmail\sendmail.exe -t'

这是在调试第 96 行的 SwiftmailerExtension.php 文件时发现的,你可以找到 if 语句,女巫可以帮助理解它是如何工作的

【讨论】:

  • 嗯,看起来很奇怪。为什么不直接把命令路径放入swiftmailer.mailers.default.command呢?通过环境变量执行此操作有什么区别?
  • 仅在环境变量的情况下,您将传递 if 块并使用工厂创建传输实例,然后才调用传输的方法 setCommand
  • 我已经更新了帖子 - 在 github 上发现了一个关于所有这些东西的未解决问题 - github.com/symfony/swiftmailer-bundle/issues/244 :) 感谢 @fritzmg 的这个测验!
猜你喜欢
  • 2013-07-03
  • 1970-01-01
  • 2021-03-01
  • 2013-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-20
  • 2019-03-29
相关资源
最近更新 更多