尽管 disable_delivery 或 delivery_address Swiftmailer 仍然发送电子邮件

Swiftmailer still sends email despite disable_delivery or delivery_address

我已经设置了暂存环境 (uat)。目的是将所有电子邮件重定向到一个电子邮件地址,或者在最坏的情况下禁用电子邮件功能。 我的问题是,尽管进行了以下设置,应用程序仍在 prod 环境中发送电子邮件。

# config_uat.yml
imports:
    - { resource: config.yml }

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            handler:      nested
        nested:
            type:  stream
            path:  "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug

swiftmailer:
    transport:      smtp
    host:           127.0.0.1
    port:           25
    encryption:     null
    sender_address: info@gpsc.cwtwebpem.com
    logging:        "%kernel.debug%"
    delivery_address: 'bastien@vial-collet.fr'
    disable_delivery: true

并且:

#config.yml
imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: "@psmdbBundle/Resources/config/services.yml" }
    - { resource: "@psmdbBundle/Resources/config/version.yml" }

# Swiftmailer Configuration
swiftmailer:
    transport:      smtp
    host:           127.0.0.1
    port:           25
    encryption:     null
    sender_address: info@domain.com
    logging:        "%kernel.debug%"

[编辑]

我已经设置了 app_uat.php。它基于 app.php:

<?php

use Symfony\Component\ClassLoader\ApcClassLoader;
use Symfony\Component\HttpFoundation\Request;

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';

// Use APC for autoloading to improve performance.
// Change 'sf2' to a unique prefix in order to prevent cache key conflicts
// with other applications also using APC.
/*
$loader = new ApcClassLoader('sf2', $loader);
$loader->register(true);
*/

//require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';

$kernel = new AppKernel('uat', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

[编辑 2] 我已经检查过,prod 环境是 运行ning 而不是 uat。 我无法将我的 apache 配置设置为 运行 uat... 这里是:

<VirtualHost *:80>
    ServerName uat.gpsc.domain.com

    DocumentRoot /var/www/vhosts/uat.gpsc.domain.com/current/web
    <Directory /var/www/vhosts/uat.gpsc.domain.com/current/web>
        AllowOverride All
        Require all granted
        Allow from All

        <IfModule mod_rewrite.c>
            Options -MultiViews
            RewriteEngine On
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*)$ app_uat.php [QSA,L]
        </IfModule>

    </Directory>

    ErrorLog /var/log/apache2/uat.project_error.log
    CustomLog /var/log/apache2/uat.project_access.log combined

</VirtualHost>

您是通过 app_uat.php 访问网站吗? (你应该在 web 目录中创建一个新的前端控制器文件)并且在那个文件中,你应该设置:

$kernel = new AppKernel('uat', true);//or 'uat', false

这是 http://symfony.com/doc/current/configuration/environments.html

中描述的过程

如果您确实创建了 app_uat.php,请更新您的答案。


编辑:这是您设置 Apache 方式的问题,因为您的 app_uat 文件似乎是正确的。但我会留下我的回答的前一部分,以防其他人需要它(这是很好的第一步)。

从你的 apache 配置文件来看,一切似乎都很好。但也请确保:

  1. 删除行 <IfModule mod_rewrite.c> 及其结束标记...所以您被迫打开重写模块! sudo a2enmod rewrite 激活 Apache 的重写模块。

  2. 确保重启apache sudo service apache2 restart

  3. AllowOverride All 意味着任何 htaccess 文件都可以覆盖该行为。确保这不会发生。通过执行 ls -a

  4. 列出 symfony 根文件夹或其 web 文件夹中的所有隐藏文件