2013-07-25 40 views
3

發送電子郵件我一直在嘗試使用swiftmailer發送電子郵件,但我不能這樣做,我得到以下異常Symfony2中無法通過Gmail

request.CRITICAL: Uncaught PHP Exception Swift_TransportException: "Failed to authenticate on SMTP server with username "[email protected]" using 1 possible authenticators" at /home/ubuntu/Symfony/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/Esmtp/AuthHandler.php line 184 [] [] 

誰能告訴我是什麼在這裏失蹤?由於某種原因,它看起來像認證失敗。

這裏是從我的配置文件中的片段:

swiftmailer:  

    transport: gmail 
    encryption: ssl 
    auth_mode: login 
    host:  smtp.gmail.com 
    username: [email protected] 
    password: password 

我開發的服務器有Ubuntu的V13 OS

+1

我有類似的問題。這個問題可能在於gmail帳戶配置。 – mika

+0

@mika我們是否在gmail中添加或授予某種權限?你確定在gmail中配置嗎? – Rahul

+1

我實際上能夠在登錄我的gmail帳戶時,在https://www.google.com/settings/security/lesssecureapps中解決此更改的配置。它可能會或可能不會阻礙你。還值得一試嗎? – mika

回答

1

嘗試從config_dev.php刪除

encryption: ssl 
auth_mode: login 

沒有必要指定加密:和auth_mode:如果您使用傳輸:gmail 請參閱symfony2.3 cookbook How to use Gmail to send Emails

快速而骯髒的方式來測試電子郵件選項。 初始化一個新的 symfony 2.3項目,並在默認控制器中的acme/DemoBundle把這個動作。在阿克米/演示/包/資源

/** 
* @Route("/mail") 
* @Template() 
*/ 
public function mailAction() { 


    $message = \Swift_Message::newInstance() 
      ->setSubject('Hello Email') 
      ->setFrom('[email protected]') 
      ->setTo('[email protected]') 
      ->setBody(
      $this->renderView(
        'DemoBundle:Default:email.txt.twig', array('name' => 'User1') 
      ) 
      ) 
    ; 
    $this->get('mailer')->send($message); 

    return array('name' => 'whatever'); 
} 

嫩枝模板/視圖/默認 前端模板

mail.html.twig

{% extends '::base.html.twig' %} 
    {% block body %} 
    This is mail template 
    {% endblock %} 

的郵件模板。 email.txt.twig

This is a test email to {{name }} 

要去/郵件要發送電子郵件。

+0

不,我試過上面的改變,我仍然收到錯誤,我也訪問了頁面如何使用電子郵件多次發送電子郵件,仍然無法使它工作 – Rahul