Symfony2 SwiftMailer不发送

时间:2014-03-14 09:10:30

标签: php symfony swiftmailer

我有一台配置了SMTP中继的Linux服务器。使用命令“mail test@test.com”它可以工作但是当我使用SwiftMailerBundle时,没有发送邮件。

日志:

[2014-03-14 10:01:06] event.DEBUG: Notified event "console.command" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onCommand". [] []
[2014-03-14 10:01:06] event.DEBUG: Notified event "console.terminate" to listener "Symfony\Bridge\Monolog\Handler\ConsoleHandler::onTerminate". [] []
[2014-03-14 10:01:06] event.DEBUG: Notified event "console.terminate" to listener "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onTerminate". [] []

Parameters.yml:

mailer_transport: mail
mailer_host: localhost
mailer_user: myusername
mailer_password: ********

我的命令:

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class AbsenceCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this
            ->setName('absence:absence')
            ->setDescription('Envoi des absences aux parents')
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {

        $message = \Swift_Message::newInstance()
            ->setSubject('Hello Email')
            ->setFrom('noreply@test.com')
            ->setTo('mymail@test.com')
            ->setBody("Test")
        ;

        $this->getContainer()->get('mailer')->send($message);

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

        $transport = $mailer->getTransport();
        if ($transport instanceof \Swift_Transport_SpoolTransport) {
            $spool = $transport->getSpool();
            $sent = $spool->flushQueue($this->getContainer()->get('swiftmailer.transport.real'));
        }

        $output->writeln("E-mail envoyé aux parents des apprentis !");
    }
}

您对解决方案有什么想法吗?

问候!

2 个答案:

答案 0 :(得分:0)

尝试安装postfix邮件服务器。 使用此命令安装postfix:sudo apt-get install postfix

答案 1 :(得分:0)

我认为这是因为 mailer_transport:参数值。尝试将其设置为 mailer_transport:smtp