如何在不使用命令的情况下从swiftmailer发送后台打印?如何在不使用命令的情况下从swiftmailer发送后台打印
php app/console swiftmailer:spool:send --env=prod
我需要把这个莫名其妙到PHP文件,使服务器管理员可以添加此附表。
如何在不使用命令的情况下从swiftmailer发送后台打印?如何在不使用命令的情况下从swiftmailer发送后台打印
php app/console swiftmailer:spool:send --env=prod
我需要把这个莫名其妙到PHP文件,使服务器管理员可以添加此附表。
只要执行与命令相同的操作即可。从命令执行()函数:
$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));
}
您需要删除$输出 - > ...线(也许你可以做一些与$送变电有用)。此外,这段代码寻找两种假脱机,也许你不需要所有的代码,如果你的假脱机不是这些类型之一。
这也可以通过How can I run symfony 2 run command from controller来实现,所以你不要复制代码。为我工作。
services.yml:
services:
swiftmailer.command.spool_send:
class: Symfony\Bundle\SwiftmailerBundle\Command\SendEmailCommand
calls:
- [ setContainer, ["@service_container"] ]
控制器代码(简化):
$this->get('swiftmailer.command.spool_send')->run(new ArgvInput(array()), new ConsoleOutput());
这绝对是更好的答案。 –
是的,这是一个官方的方式来做到这一点 - http://symfony.com/doc/3.2/console/command_in_controller.html –
工作就像一个魅力:)谢谢卡洛斯 – Tom