2017-01-30 82 views
0

我想使用symfony發送電子郵件,但swiftmailer不發送任何電子郵件。我甚至沒有得到錯誤報告或其他任何東西。這就是我的代碼:swiftmailer不發送電子郵件

$mail = \Swift_Message::newInstance() 
       ->setSubject('Subject') 
       ->setTo('[email protected]') #this is replaced by real email of course 
       ->setFrom('[email protected]') 
       ->setBody('Testbody'); 

     $this->get('mailer')->send($mail); 

那的配置:

swiftmailer: 
default_mailer: mailer 
mailers: 
    mailer: 
     transport: "%mailer_transport%" 
     host:  "%mailer_host%" 
     username: "%mailer_user%" 
     password: "%mailer_password%" 
     #spool:  { type: memory } 

我什至主機設置爲不存在的地址,但我不從swiftmailer或symfony中得到任何錯誤。

我試圖找到的lib文件,但在symfony的任何地方的文件沒有Swift_Message或的newInstance,奇怪

+1

你正在使用SM config正在使用的參數是什麼?你也有一個運行郵件服務器? – stevenll

+1

你想擁有我的郵件服務器憑據嗎? :)它的外部郵件服務器。例如,當我將服務器主機更改爲非工作地址時,如果外部郵件工作正常,我甚至不會收到swiftmailer – Asara

+0

的任何錯誤,那麼此處顯示的代碼看起來不錯。你確定沒有別的東西阻止你的代碼發送消息嗎? – stevenll

回答

0

使用此代碼

$message = \Swift_Message::newInstance() 
      ->setSubject('Validation de votre commande') 
      ->setFrom('[email protected]') 
      ->setTo('[email protected]') 
      ->setBody('Testbody'); 
      ->setCharset('utf-8') 
      ->setContentType('text/html') 
      ->setBody('test'); 

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

/配置/ parametres.yml :

mailer_transport: gmail 
mailer_host: smtp.gmail.com 
mailer_user: your mail 
mailer_password: your password mail 
在app

/配置/ config.yml:

# Swiftmailer Configuration 
swiftmailer: 
    transport: "%mailer_transport%" 
    host:  "%mailer_host%" 
    username: "%mailer_user%" 
    password: "%mailer_password%" 
    spool:  { type: memory } 
+0

爲什麼你認爲我有一個Gmail帳戶? – Asara

+0

最好的解決方案是使用gmail帳戶 –

+0

該評論應該是負面選票。這是非常遠離解決方案 – Asara

0

我曾經見過有同樣問題的人。對他來說問題在於線軸隊列。它是通過明確禁止任何解決閥芯:

spool: 
     enabled:false 

或代碼沖洗隊列:

$this->get('mailer')->send($mail); 
$spool = $this->get('mailer')->getTransport()->getSpool(); 
$spool->flushQueue($this->get('mailer')->getTransport()); 

希望工程!

+0

,你可以看到我的問題,sppol沒有激活,我甚至檢查它,但沒有找到郵件那裏 – Asara

相關問題