2016-11-05 162 views
0

我想通過使用Symfony 3.1和SwiftMailer發送測試郵件,但它不起作用。我正在閱讀其他解決方案,但仍然無法正常工作。Symfony 3.1 swiftmailer電子郵件不發送

Config.yml:

swiftmailer: 
    transport: %mailer_transport% 
    encryption: %mailer_encryption% 
    auth_mode: %mailer_auth_mode% 
    host:  %mailer_host% 
    username: %mailer_user% 
    password: %mailer_password% 
    spool:  { type: memory } 

Parameters.yml

mailer_transport: smtp 
    mailer_encryption: ssl 
    mailer_auth_mode: login 
    mailer_host: smtp.gmail.com 
    mailer_user: [email protected] 
    mailer_password: mypass 

Parameters.yml第2節我嘗試:

mailer_transport: gmail 
     mailer_encryption: ssl 
     mailer_auth_mode: login 
     mailer_host: smtp.gmail.com 
     mailer_user: [email protected] 
     mailer_password: mypass 

控制器:

public function contactAction(Request $request) 
    { 
     $name = $request->request->get('name'); 
     $surname = $request->request->get('surname'); 
     $email = $request->request->get('email'); 
     $subject = $request->request->get('subject'); 
     $message = $request->request->get('message'); 
     $data = ""; 
     if($request->request->get('contact_submit')){ 

      $message = \Swift_Message::newInstance() 
       ->setSubject($subject) 
       ->setFrom($email) 
       ->setTo('[email protected]') 
       ->setBody($message); 

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

      $data = "Thank you: $name"; 

     } 
     return $this->render('przedszkole/contact.html.twig', array('data' => $data));  
    } 

所以點擊提交後,我的看法改變,讓我看看:謝謝$名字,但我沒有得到任何電子郵件:/

我改變我的Gmail電子郵件的安全拉特就像有人告訴其他解決方案,但它對我沒有幫助:/

我還取消了swiftmailer:config_dev.yml中的delivery_adress。

我會感謝任何幫助:/

+0

您是否嘗試過這裏討論的解決方案:http://stackoverflow.com/questions/3478906/using-phps-swiftmailer-with-gmail – LBA

+0

您使用的是哪個版本的PHP?你看到服務器日誌或Symfony工具欄中的相關錯誤嗎? –

+0

PHP 5.6.23。我不會在任何地方看到任何錯誤。 – Abdulos

回答

0

你怎麼樣用頭(只)以下YML配置:

mailer_transport: gmail 
    mailer_user: [email protected] 
    mailer_password: mypass 

,我讀了有你不需要的默認設置設置爲Gmail,也許因爲你正在設置,它有一些影響。我不確定這是否能解決問題,但您可以嘗試。

+0

它沒有幫助:/ – Abdulos

0

我想這個問題可能是電子郵件進入假脫機隊列。我也曾與其他人見面。您可以通過顯式地禁用它:

spool: 
    enabled: false 
0

我有機會來調試你的代碼,我得到的是你需要改變這兩條線

->setFrom($email) 
->setTo('[email protected]') 

->setFrom('[email protected]') 
->setTo($email) 

setFrom()將包含您的電子郵件ID和setTo()將具有收件人ID。

相關問題