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));
}
あなたは$出力を削除する必要がある - > ...ライン(多分あなたは$送ら変数で有用な何かを行うことができます)。また、このコードは2種類のスプールを探しますが、あなたのスプールがこの種のものでない場合は、すべてのコードを必要としないかもしれません。
これは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