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

时间:2017-12-28 16:02:56

标签: php symfony smtp

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

我遵循了此文档[https://docs.platform.sh/administration/web/email.html#sending-e-mail][1]

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

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)". 

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

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

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

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

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

@Test(expected=DuplicationException.class)
public void saveFailedWithDuplicatedAccount(){
    memberServiceImpl.save(member);
    memberServiceImpl.save(member);
}

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

非常感谢!

1 个答案:

答案 0 :(得分:2)

看起来您使用的是旧的Symfony 3x版本。 {3.2}版本中引入了%env()%语法。作为解决方法,您可以在配置目录中创建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