无法使用 SwiftMailer 和 Symfony 2 发送电子邮件

Cannot send an email using SwiftMailer and Symfony 2

我正在尝试使用 SwiftMailer 和 Symfony2 发送电子邮件。

之前我有一个Can't connect to smtp.gmail.com问题,但是知道,我没有任何错误,但是消息仍然没有发送。

这是我的 config.yml :

swiftmailer:
    transport: mail
    encryption: ssl
    host: smtp.gmail.com
    port: 465
    auth_mode: login
    username:   myUsername@gmail.com
    password:   myPassword

config_test.yml :

swiftmailer:
    disable_delivery: false

控制器发送:

$message = \Swift_Message::newInstance(null)
   ->setSubject('Test')
   ->setFrom('test@gmail.com')
   ->setTo('test@gmail.com')
   ->setBody('Test test test !!');

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

我尝试了很多在互联网上找到的修复方法,但没有任何修复方法:/

我正在尝试使用 Wamp 本地发送

编辑:

我已经将传输设置为 SMTP,现在,当我使用端口 443 时,我会超时,如果我使用 465,我只会再次 "can't connect"。

编辑 2:

我尝试使用 "Transport: gmail",但仍然显示 "can't connect" 消息 这是我的配置:

transport: gmail
username:  'myEmail@gmail.com'
password:  'myPassword'

要使用 Gmail 发送邮件,您可以使用 transport: gmail

如果您需要更多信息: http://symfony.com/doc/current/cookbook/email/gmail.html

如果配置良好但无法正常工作,请检查您的安全环境(防火墙,...)

在App/config/config.yml 你写这个:

swiftmailer:
transport: smtp
encryption: ssl     
auth_mode:  login   
host: "%mailer_host%"
username:  "%mailer_user%"
password:  "%mailer_password%"
spool:     { type: memory }

在App/config/parameters.yml:

 mailer_transport: gmail
    mailer_host: smtp.gmail.com
    mailer_user: yourmail@gmail.com
    mailer_password: your_mail_password

在您的控制器中:

public function sendMailAction() { 

      $Request= $this ->getRequest();

      if($Request ->getMethod()== "POST"){

          $name= $Request -> get("name");
          $email = $Request -> get("email");
          $sujet = $Request -> get("subject");
          $message = $Request -> get("message");

          $mailer = $this->container->get('mailer');
          $transport = \Swift_SmtpTransport::newInstance('smtp.gmail.com',465,'ssl')
                  ->setUsername('******')
                  ->setPassword('******');

           $sms = \Swift_Message::newInstance('Test')
                   ->setSubject($sujet)
                   ->setFrom('your_mail_here@gmail.com')
                   ->setTo($email)
                   ->setBody($message);

$spool = $mailer->getTransport()->getSpool();
$transport = $this->get('swiftmailer.transport.real');

$spool->flushQueue($transport);
           $this->get('mailer')->send($sms);

      }
      return $this->render('SwiftMailSwiftMailBundle:Mail:contact.html.twig');   

      }

如果你want.Good运气好

让我把完整的项目发给你