简体   繁体   English

从 php.ini 配置 SMTP 主机

[英]Configure SMTP host from php.ini

I'm trying to configure SwiftMailer's SMTP transport by looking at php.ini.我正在尝试通过查看 php.ini 来配置 SwiftMailer 的 SMTP 传输。 I've tried creating a compilerpass to alter the mailer_host parameter, but the changed value doesn't seem to influence the container that gets built.我尝试创建一个 compilerpass 来更改 mailer_host 参数,但更改后的值似乎不会影响构建的容器。

On a second attempt, I tried requesting the service definition for swiftmailer.mailer.default.transport."something", but can't seem to find the correct service either.在第二次尝试中,我尝试请求 swiftmailer.mailer.default.transport."something" 的服务定义,但似乎也找不到正确的服务。

Any pointers?任何指针?

Thanks谢谢

Ok, I found out that I can alter the configuration of other bundles using the PrependExtensionInterface.好的,我发现我可以使用 PrependExtensionInterface 更改其他包的配置。 After implementing that interface in my own extension, I could just do this:在我自己的扩展中实现该接口后,我可以这样做:

public function prepend(ContainerBuilder $container)
{
    $container->prependExtensionConfig(
        'swiftmailer', 
        array ('host' => ini_get('SMTP'))
    );
}

I'm aware there are probably better solutions for this.我知道可能有更好的解决方案。 For instance, placing the swiftmailer configuration in a server-wide .yml file and including that.例如,将 swiftmailer 配置放在服务器范围的 .yml 文件中并包含该文件。 That would offer more flexibility etc., but for now, this is fine.这将提供更多的灵活性等,但就目前而言,这很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM