0

I try to send email with symfony. I use this code :

$email = (new TemplatedEmail())
        ->from('myemail@mydomain.com')
        ->to('mypersonnaltestingemail@gmail.com')
        ->subject('Nouvelle demande de devis !')
        ->htmlTemplate('email/email_project_ask.html.twig')
        ->context([
            'projectAsk' => $projectAsk,
        ])
    ;

    try {
        $this->mailer->send($email);
    } catch (TransportExceptionInterface $e) {
        return new RedirectResponse($this->router->generate('app_404_error'));
    }

Previously, the same code sent emails, I could not explain what have changed and provoke an error. I writed in my .env file the mailer DSN and even tried to change it (the password for example).

MAILER_DSN=smtp://myemail@mydomain.com:mypassword@mx1.mail.ovh.net

In the profiler, the email is "sent" from the email written in the function.

Image of the profiler which displays that email is sent

But in the facts, when I connect to mypersonnaltestingemail@gmail.com, in my mailbox, I don't see the email...

Can someone could explain me where is the problem and how i can solve it? In the DSN? I am working online in a testing domain like test.mydomain.com... Previously the function and the mailer DSN worked...

  • Do you have a `.env.local` file that might be trumping this? Also, have you gone through [all the steps here](https://stackoverflow.com/a/24644450/231316)? – Chris Haas Jul 18 '22 at 14:21
  • The values and the DSN are in a .env.local, not in a .env file, sorry... – Léane Barbotin Jul 18 '22 at 14:29
  • And yes, all the steps are done... – Léane Barbotin Jul 18 '22 at 14:29
  • Also check your SPF records to make sure you are authorized to send in that fashion – Chris Haas Jul 18 '22 at 14:32
  • Did you check other boxes such as spam? for debugging just login from any email client to this email, and try to send emails. If you can send it from email client but not from symfony then search problem in symfony. as @ChrisHaas mentioned it might be server configuration problems. – Nuryagdy Mustapayev Jul 18 '22 at 14:49
  • I just tried with another smtp with gmail. I have the same problem. Maybe it's a problem with symfony, but I don't really know how to have more information than I have in the profiler... The profiler doesn't give me a lot of informations. – Léane Barbotin Jul 18 '22 at 14:57
  • With gmail, it's not possible to have server configuration problems I think ? – Léane Barbotin Jul 18 '22 at 14:58
  • Gmail has rules for interacting with it, just like every MTA out there. SPF, DKIM, TLS, ports, etc. – Chris Haas Jul 18 '22 at 15:12
  • Also, as I remember you need to set up different password for gmail account https://support.google.com/accounts/answer/185833?hl=en. And as I said before, download ex. Thunderbird email client, login to your email with app password you generated and try to send email – Nuryagdy Mustapayev Jul 19 '22 at 06:45
  • Please show `config/packages/dev/mailer.yaml` – Arleigh Hix Nov 02 '22 at 19:31

1 Answers1

0

If you installed Symfony with the --docker option, your docker-compose.override.yml file will contain a configuration for mailcatcher when you add symfony mailer.

Hover over "Server" in your profiler bar to reveal a menu and open Webmail from there. Your email should be there.

Martin Fall
  • 121
  • 7