2014-03-14 41 views
1

我有一個配置了SMTP中繼的Linux服務器。使用命令「mail [email protected]」它可以工作,但是當我使用SwiftMailerBundle時,不會發送郵件。Symfony2 SwiftMailer不發送

日誌:

[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('[email protected]') 
      ->setTo('[email protected]') 
      ->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 !"); 
    } 
} 

你對溶液中的任何想法?

問候!

回答

0

嘗試安裝postfix郵件服務器。 使用此命令來安裝postfix:sudo apt-get install postfix

+0

這是什麼?我沒有此服務器上的管理員權限。 – Servietsky

+0

@Servietsky:在這種情況下,您可能已經安裝了郵件服務器。嘗試通過Outlook,Thunderbird或任何其他方式連接到您的服務器,以確保您的郵件服務已啓動並正在收聽,並且您的憑證正常工作。 –

0

我相信這是因爲mailer_transport:參數值。嘗試將其設置爲mailer_transport:smtp

+0

我已經試過了。 – Servietsky

+0

我也是這樣,不工作,我的默認已經是smtp了。請注意,我剛剛做了一個作曲家更新之前,我得到這個錯誤,它確實更新迅捷郵件。 ' - 刪除swiftmailer/swiftmailer(v5.1.0) - 安裝swiftmailer/swiftmailer(v5.2.0)'任何解決方案呢? – blamb