在platform.sh为Symfony 3项目配置smtp

问题描述 投票:1回答:1

我尝试在platform.sh上为我的Symfony 3项目配置SMTP,但我没有让它工作。

我按照这个文档[https://docs.platform.sh/administration/web/email.html#sending-e-mail][1]

我无法编辑parameters.yml,因为它是在构建过程中生成的。所以我试着编辑paramters.yml.dist。并使用以下代码更新它:

mailer_transport:  smtp
mailer_host:       "%env(PLATFORM_SMTP_HOST)%"
mailer_user:       null
mailer_password:   null

当我这样做时,我将在构建期间收到以下错误消息:

W:   [RuntimeException]                                                               
W:   An error occurred when executing the "'cache:clear --no-warmup'" command:        
W:                                                                                    
W:     [Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException]    
W:     You have requested a non-existent parameter "env(platform_smtp_host)". 

所以我尝试编辑paramters_platform.php并添加以下代码:

$container->setParameter('mailer_host','%env(PLATFORM_SMTP_HOST)%');

然后构建过程将工作,但我在加载网站时收到以下错误消息:

ParameterNotFoundException in ParameterBag.php line 84:
You have requested a non-existent parameter "env(platform_smtp_host)".
in ParameterBag.php line 84
at ParameterBag->get('env(platform_smtp_host)') in ParameterBag.php line 200
at ParameterBag->resolveString('%env(PLATFORM_SMTP_HOST)%', array('mailer_host' => true, 'env(platform_smtp_host)' => true)) in ParameterBag.php line 171
at ParameterBag->resolveValue('%env(PLATFORM_SMTP_HOST)%', array('mailer_host' => true)) in ParameterBag.php line 200
at ParameterBag->resolveString('%mailer_host%', array('mailer_host' => true)) in ParameterBag.php line 171
at ParameterBag->resolveValue('%mailer_host%', array()) in ParameterBag.php line 161
at ParameterBag->resolveValue(array('transport' => '%mailer_transport%', 'host' => '%mailer_host%', 'username' => '%mailer_user%', 'password' => '%mailer_password%'), array()) in ParameterBag.php line 161
at ParameterBag->resolveValue(array(array('transport' => '%mailer_transport%', 'host' => '%mailer_host%', 'username' => '%mailer_user%', 'password' => '%mailer_password%'))) in MergeExtensionConfigurationPass.php line 45
at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in MergeExtensionConfigurationPass.php line 39
at MergeExtensionConfigurationPass->process(object(ContainerBuilder)) in Compiler.php line 104
at Compiler->compile(object(ContainerBuilder)) in ContainerBuilder.php line 597
at ContainerBuilder->compile() in bootstrap.php.cache line 2687
at Kernel->initializeContainer() in bootstrap.php.cache line 2465
at Kernel->boot() in bootstrap.php.cache line 2496
at Kernel->handle(object(Request)) in app_dev.php line 30

有没有人设法让SMTP在plaform.sh上工作?或者有没有人知道如何摆脱这个问题?

非常感谢你!

php symfony smtp
1个回答
2
投票

看起来你正在使用旧的Symfony 3x版本。 %env()%语法在3.2版本中引入。作为解决方法,您可以在配置目录中创建parameters.php文件,并将其导入config.yml。在这个文件里面只需使用getenv() php函数设置所需的容器参数:

<?php

$container->setParameter('mailer_host', getenv('PLATFORM_SMTP_HOST'));

一些文章:

设置外部参数:http://symfony.com/doc/3.3/configuration/external_parameters.html getenv():http://php.net/manual/en/function.getenv.php

© www.soinside.com 2019 - 2024. All rights reserved.