如何在不使用命令的情况下从swiftmailer发送假脱机 [英] How to send spool from swiftmailer without using command
问题描述
如何在不使用命令的情况下从swiftmailer发送假脱机?
How to send spool from swiftmailer without using command?
php app/console swiftmailer:spool:send --env=prod
我需要以某种方式将其放入php文件中,以便服务器管理员可以将其添加到计划中.
I need to put this somehow into php file so that Server admin can add this to Schedule.
推荐答案
执行与命令相同的操作.通过命令Execute()函数:
Just do the same that the command does. From the command Execute() function:
$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));
}
您需要删除$ output-> ...行(也许您可以对$ sent变量做一些有用的事情).另外,此代码查找两种类型的假脱机,如果您的假脱机类型不是其中之一,则可能不需要所有代码.
You need to remove the $output->... line (maybe you can do something useful with the $sent variable). Also, this code looks for two kinds of spool, maybe you don´t need all the code if your spool is not one of these kinds.
这篇关于如何在不使用命令的情况下从swiftmailer发送假脱机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!