Sending mail with Symfony (SwiftMail & Gmail)

1k views Asked by At

I'm trying to use Swiftmailer with Symfony 2.4.

Here is my config.yml :

# This file is auto-generated during the composer install
# parameters:
# mailer_transport: gmail
# mailer_host: smtp.gmail.com
# mailer_user: [email protected]
# mailer_password: XXXXXX
# mailer_port: 465
# locale: fr
# secret: XXXX

And this is parameters.yml

# Swiftmailer Configuration
#  swiftmailer:
#     transport: %mailer_transport%
#     username:  %mailer_user%
#     password:  %mailer_password%

My code is pretty basic :

#   $request = $this->get('request');
#   $dataSubject = $request->query->get('lbSubject');
#   $dataEmail = $request->query->get('lbEmail');
#   $dataMessage = $request->query->get('lbMessage');
#   //Récupération du service
#    $mailer = $this->get('mailer');
#   
#   // Création de l'e-mail : le service mailer utilise SwiftMailer, donc nous créons une instance de Swift_Message
#    $message = \Swift_Message::newInstance()
#       ->setSubject($dataSubject)
#       ->setFrom($dataEmail)
#       ->setTo('[email protected]')
#       ->setBody($dataMessage);
#
#   try 
#   {
#        if (!$mailer->send($message, $failures))
#        {
#           return new Response('Erreur' . $failures,400);
#        }
#        return new Response('OK',200);
#   }
#   catch(Exception $e)
#   {
#       return new Response('Erreur' . $failures,400);
#   }

At the end, it returns an error

Connection could not be established with host smtp.gmail.com

This is pretty offensive because i know my password .

After a few minutes, i receive and email that tells me that someone tried to hack my account etc ...

Oh and i'm running this with Wamp, so in local.

Is this my code that has a problem or Google maybe ?

Thanks

1

There are 1 answers

1
jmluy On

Try adding the following to your swiftmail configuration as GMail requires encryption/ssl connection

encryption: ssl