0
votes

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: [email protected]
    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: [email protected]
        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('[email protected]')
                ->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 :/

3
did you try the solution discussed here: stackoverflow.com/questions/3478906/…LBA
Which version of PHP are you using? Do you see some related error looking the server log or in the Symfony toolbar?gp_sflover
PHP 5.6.23. I dont' see any error anywhere.Abdulos
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('[email protected]') ->setPassword('pass'); $mailer = \Swift_Mailer::newInstance($transporter);'Abdulos

3 Answers

0
votes

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

mailer_transport: gmail
     mailer_user: [email protected]
     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.

0
votes

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
0
votes

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

->setFrom($email)
->setTo('[email protected]')

as

->setFrom('[email protected]')
->setTo($email)

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