0

I have some problem with swiftmailer in symfony4. When I send email, I don't get any error and Symfony Profiler display something like that:

https://i.stack.imgur.com/tCYc0.png

But I don't get email on my gmail. And I don't really understand what email should be in setFrom(), is there should not be email which I use in my env?? Here is controller

 public function sendMessage(\Swift_Mailer $mailer)
{
    $request = Request::createFromGlobals();
    $values = [];

    $values['name'] = $request->request->get('name');
    $values['phone_number'] = $request->request->get('phone_number');
    $values['email'] = $request->request->get('email');
    $values['message'] = $request->request->get('message');


    $message = (new \Swift_Message('Message from example.org'))
        ->setFrom($values['email'])
        ->setTo('mail@example.com')
        ->setBody($this->renderView('email.html.twig',
                array('name' => $values['name'], 'phone_number' => $values['phone_number'], 'message' => $values['message'])
            ), 'text/html');

    $mailer->send($message);

    return new Response('Thank you for your email');
}

and configuration in .env file

MAILER_URL="gmail://myUsername:myPassword@smtp.gmail.com"

Somebody know what is wrong?

LuFFy
  • 8,799
  • 10
  • 41
  • 59
Otix12
  • 1
  • 1
  • Possible duplicate of [mailer symfony 4 not working](https://stackoverflow.com/questions/48230130/mailer-symfony-4-not-working) – Dirk J. Faber Jul 19 '18 at 19:44

1 Answers1

0

This is an issue with Gmail, not with swiftmailer. If you use another mail server you won't have this problem. See also: this same question.

Dirk J. Faber
  • 4,360
  • 5
  • 20
  • 58
  • So I change mailer_url, and now this look like that: MAILER_URL="smtp://serwer9999999.home.pl" And I get the same result. – Otix12 Jul 22 '18 at 13:15
  • Do you have a working mail server? Configuration could look something like this: `MAILER_URL=smtp://mail.server.com:465?encryption=ssl&auth_mode=login&username=your@username.com&password=yourpassword` – Dirk J. Faber Jul 22 '18 at 13:24
  • Ok, I did that, and now it's problem with connection, perhaps @ in my username can be a problem? – Otix12 Jul 24 '18 at 17:41
  • This completely depends on your mailserver. Some servers have a username that is like an email-address others can simply be 'somename'. You have to find out which is your username you need to use the server. – Dirk J. Faber Jul 24 '18 at 17:52
  • So connection works, but now I have something like that Exception occurred while flushing email queue: Expected response code 250 but got code "550", with message "550 5.1.8 Sender address rejected ", and with the same configuration it didn't show up earlier. – Otix12 Jul 25 '18 at 17:11