如何在不使用命令的情况下从swiftmailer发送假脱机

Tom*_*Tom 8 spool swiftmailer symfony

如何在不使用命令的情况下从swiftmailer发送假脱机?

php app/console swiftmailer:spool:send --env=prod

我需要以某种方式将其放入php文件中,以便服务器管理员可以将其添加到Schedule.

Fox*_*ion 22

这也可以通过如何从控制器运行symfony 2 run命令来实现,因此您不需要重复代码.为我工作.

services.yml:

services:
    swiftmailer.command.spool_send:
        class: Symfony\Bundle\SwiftmailerBundle\Command\SendEmailCommand
        calls:
            - [ setContainer, ["@service_container"] ]
Run Code Online (Sandbox Code Playgroud)

控制器代码(简化):

$this->get('swiftmailer.command.spool_send')->run(new ArgvInput(array()), new ConsoleOutput());
Run Code Online (Sandbox Code Playgroud)


Car*_*dos 13

就像命令一样.从命令Execute()函数:

    $mailer     = $this->getContainer()->get('mailer');
    $transport  = $mailer->getTransport();

    if ($transport instanceof \Swift_Transport_SpoolTransport) {
        $spool = $transport->getSpool();
        if ($spool instanceof \Swift_ConfigurableSpool) {
            $spool->setMessageLimit($input->getOption('message-limit'));
            $spool->setTimeLimit($input->getOption('time-limit'));
        }
        if ($spool instanceof \Swift_FileSpool) {
            if (null !== $input->getOption('recover-timeout')) {
                $spool->recover($input->getOption('recover-timeout'));
            } else {
                $spool->recover();
            }
        }
        $sent = $spool->flushQueue($this->getContainer()->get('swiftmailer.transport.real'));

        $output->writeln(sprintf('sent %s emails', $sent));
    }
Run Code Online (Sandbox Code Playgroud)

你需要删除$ output - > ...行(也许你可以用$ sent变量做一些有用的事情).此外,此代码查找两种假脱机,如果您的假脱机不是这些类型之一,您可能不需要所有代码.