Php symfony2无法通过gmail发送电子邮件

Php symfony2无法通过gmail发送电子邮件,php,gmail,swiftmailer,symfony-2.2,Php,Gmail,Swiftmailer,Symfony 2.2,我一直在尝试用swiftmailer发送电子邮件,但我不能这样做,我得到以下异常 request.CRITICAL: Uncaught PHP Exception Swift_TransportException: "Failed to authenticate on SMTP server with username "myusername@gmail.com" using 1 possible authenticators" at /home/ubuntu/Symfony/vendor/sw

我一直在尝试用swiftmailer发送电子邮件,但我不能这样做,我得到以下异常

request.CRITICAL: Uncaught PHP Exception Swift_TransportException: "Failed to authenticate on SMTP server with username "myusername@gmail.com" 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:   myusername@gmail.com
  password:   password

我的开发服务器有ubuntu v13操作系统

请尝试从您的配置中删除\u Dev.php

encryption: ssl
auth_mode:  login
如果您使用的是transport:gmail,则无需指定加密:和身份验证模式 请参阅symfony2.3食谱

快速和肮脏的方式来测试电子邮件选项。 初始化一个新的symfony 2.3项目,并在acme/DemoBundle的默认控制器中执行此操作

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


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

    return array('name' => 'whatever');
}
Acme/Demo/Bundle/Resources/views/Default中的细枝模板 前端模板

mail.html.twig

{% extends '::base.html.twig' %}
  {% block body %}
     This is mail template 
  {% endblock %}
邮件程序模板。 email.txt.twig

This is a test email to {{name }}

转到/mail应该会发送电子邮件。

不,我尝试了上述更改,但仍然出现错误,而且我多次访问了如何使用电子邮件发送电子邮件的页面,仍然无法使其正常工作。我遇到了类似的问题。问题可能出在gmail帐户配置上。@mika我们在gmail中添加或授予某种权限了吗?你确定gmail中的配置吗?在登录我的gmail帐户时,我实际上能够在中解决这个不断变化的配置。它可能会也可能不会阻碍你。还值得一试吗?