Komut kullanmadan swiftmailer spool nasıl gönderilir?Komut kullanmadan swiftmailer spool nasıl gönderilir
php app/console swiftmailer:spool:send --env=prod
O Sunucu yönetici bu planla eklemek böylece php dosyasına bir şekilde bu koymak gerekir.
Komut kullanmadan swiftmailer spool nasıl gönderilir?Komut kullanmadan swiftmailer spool nasıl gönderilir
php app/console swiftmailer:spool:send --env=prod
O Sunucu yönetici bu planla eklemek böylece php dosyasına bir şekilde bu koymak gerekir.
Sadece komutun aynısını yapın. komutunu() işlevini yürütün:
$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));
}
Sen $ çıkışını kaldırmak gerekir -> ... çizgi (belki $ gönderilen değişkenle yararlı bir şeyler yapabilirsiniz). Ayrıca, bu kod biriktirme iki çeşit için arar, belki de bu türlerden biri değilse, tüm kodu gerekmez.
Bu, How can I run symfony 2 run command from controller ile de elde edilebilir, bu nedenle kodu çoğaltmazsınız. Benim için çalıştı.
services.yml:
services:
swiftmailer.command.spool_send:
class: Symfony\Bundle\SwiftmailerBundle\Command\SendEmailCommand
calls:
- [ setContainer, ["@service_container"] ]
Kontrolör kodu (basitleştirilmiş): Bir cazibe gibi çalıştı
$this->get('swiftmailer.command.spool_send')->run(new ArgvInput(array()), new ConsoleOutput());
Bu kesinlikle daha iyi cevaptır. –
Evet ve bunu yapmanın resmi bir yolu budur - http://symfony.com/doc/3.2/console/command_in_controller.html –
:) teşekkürler Carlos – Tom