0

I wanted to send a test email by using Symfony 3.1 and SwiftMailer, but it doesn't work. I was reading other solutions, but it still doesn't work.

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: user@gmail.com
    mailer_password: mypass

Parameters.yml v.2 I was trying:

 mailer_transport: gmail
        mailer_encryption: ssl
        mailer_auth_mode: login
        mailer_host: smtp.gmail.com
        mailer_user: user@gmail.com
        mailer_password: mypass

Controller:

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('myemail@gmail.com')
                ->setBody($message);

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

            $data = "Thank you: $name";

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

So after click Submit, my view change and show me: Thank you $name, but i don't get any email :/

I change security lvl of my gmail e-mail like someone tell in other solutions, but it doesn't help for me :/

I also uncomment swiftmailer: delivery_adress in config_dev.yml.

I will be grateful for any help :/

Abdulos
  • 1
  • 3
  • did you try the solution discussed here: http://stackoverflow.com/questions/3478906/using-phps-swiftmailer-with-gmail – LBA Nov 05 '16 at 15:56
  • Which version of PHP are you using? Do you see some related error looking the server log or in the Symfony toolbar? – gp_sflover Nov 05 '16 at 16:57
  • PHP 5.6.23. I dont' see any error anywhere. – Abdulos Nov 06 '16 at 07:59
  • I tried to add but it didn't change anything. Im sure that i did something stupid and i don't see it now: ' $transporter = \Swift_SmtpTransport::newInstance('ssl://smtp.gmail.com', 465, 'ssl') ->setUsername('mymaili@gmail.com') ->setPassword('pass'); $mailer = \Swift_Mailer::newInstance($transporter);' – Abdulos Nov 06 '16 at 08:01

3 Answers3

0

How about you use (only) the following YML config:

mailer_transport: gmail
     mailer_user: user@gmail.com
     mailer_password: mypass

I read that there are default settings that you don't need to set for gmail and maybe because you are setting, it has some effect. I'm not sure if this will fix the problem, but you can try it.

Alvin Bunk
  • 7,621
  • 3
  • 29
  • 45
0

I guess the problem might be with emails going into spool queue. This I had seen with someone else as well. You can explicitly disable it using:

spool:
     enabled: false
Piyush Singh
  • 67
  • 1
  • 6
0

I got a chance to debug your code and all I get is you need to change these two lines

->setFrom($email)
->setTo('myemail@gmail.com')

as

->setFrom('myemail@gmail.com')
->setTo($email)

setFrom() will contain your email ID and setTo() will have the recipients ID.

Shahroze Nawaz
  • 589
  • 5
  • 9