0

i use Symfony6.2 Mailer to sent an email like this docs

https://symfony.com/doc/current/mailer.html but the mail is not sent (i cannnot see any new mail in the inbox ) and i dont have any errror?! my mailer.yaml

\`\`\`framework:
    mailer:
        transports:
            main: '%env(MAILER_DSN)%'

i tried to debug using php bin/console mailer:test ,the mail sent successfully nut when i use this command but when i use the Route function

    {
        $email = (new Email())
            ->from('hello@example.com')
            ->to('you@example.com')
            //->cc('cc@example.com')
            //->bcc('bcc@example.com')
            //->replyTo('fabien@example.com')
            //->priority(Email::PRIORITY_HIGH)
            ->subject('Time for Symfony Mailer!')
            ->text('Sending emails is fun again!')
            ->html('<p>See Twig integration for better HTML integration!</p>');

        $mailer->send($email);

        // ...
    }
}

i dont recieve any mail i exepct to find new mail in the inbox using the ROute

HAron
  • 43
  • 7
  • Not _sent_ successfully? Or not _received_ successfully? Those are two very different things, and there is a lot which can go wrong in between. What value does `$mailer->send` return? I note that currently your code doesn't seem to test it. Or does it throw an exception? See also https://symfony.com/doc/current/mailer.html#handling-sending-failures . If the PHP code isn't throwing an exception, then the issue is more likely to be within the mailserver - if you have access, check its logs. – ADyson Aug 30 '23 at 15:56
  • yeah i also tried ```$email = new Email(); // ... try { $mailer->send($email); } catch (TransportExceptionInterface $e) { // some error prevented the email sending; display an // error message or try to resend the message }``` and i dont have any Exception @ADyson – HAron Aug 30 '23 at 16:02
  • Ok. Probably it's time to investigate the mailserver in more detail, then. As the documentation says: _"Symfony Mailer considers that sending was successful when your transport (SMTP server or third-party provider) accepts the mail for further delivery. The message can later be lost or not delivered because of some problem in your provider, but that's out of reach for your Symfony application."_ – ADyson Aug 30 '23 at 16:03
  • Of course, your code can still contribute to the problem, for example one common mistake that people make is trying to set a fake value for "from", or a value which isn't in the email server's domain (this can make the mail look like a spam or spoofing attempt, causing mailservers to discard it). – ADyson Aug 30 '23 at 16:05
  • well i use gmail as a MAILER_DSN. so what i can do if its got lost hh? @ADyson – HAron Aug 30 '23 at 16:05
  • Only just ensure that the mail has valid from and to values, mainly. Ensure that the "from" value is the same as the gmail account email that you use to authenticate with gmail in your symfony settings, would be the main thing I think. – ADyson Aug 30 '23 at 16:08
  • You may also get some useful info by examining the SentMessage object returned by the send() call - see https://symfony.com/doc/current/mailer.html#debugging-emails – ADyson Aug 30 '23 at 16:09
  • all is good i check it more thank 100 times :(@ADyson if you wanti can provide the github link – HAron Aug 30 '23 at 16:10
  • You checked the SentMessage object too? Don't need your GitHub but you can provide a [mre] of the issue here if you like including the settings (but don't give your real password, and you can redact the email address for privacy too). Just [edit] your question. – ADyson Aug 30 '23 at 16:11
  • Can we also assume that you've taken into account existing info about configuring symfony with gmail, such as the various instructions [here](https://stackoverflow.com/questions/63710048/try-to-use-symfony-mailer-with-gmail)? – ADyson Aug 30 '23 at 16:12
  • no this is ot my case i dont have the ssl error it's from the firewell and i git diseable it – HAron Aug 30 '23 at 16:15
  • 1
    Does Symfony's Profiler contain more details about this? Or your server's log file (which could indicate whether the PHP process was able to forward the mail through your server's outgoing mail server)? – Nico Haase Aug 30 '23 at 16:17
  • It's not just about SSL. Read _all_ the answers. And that's just one link, it was an _example_ of the multitude of information you can find if you put "symfony mailer gmail" into a search engine. My point was, have you done all the possible research and followed all the possible guidance? We don't really know, since you shared only minimal info about your setup and your debugging efforts. – ADyson Aug 30 '23 at 16:19
  • i just find it's Queued [link](https://ibb.co/GCjwmdw) @ADyson – HAron Aug 30 '23 at 16:28
  • [link](https://ibb.co/pfcZ6Mq) Log file – HAron Aug 30 '23 at 16:30
  • i resolved my problem with : add the option message_bus: false in my config/packages/mailer.yaml: framework: mailer: dsn: '%env(MAILER_DSN)%' message_bus: false – HAron Aug 30 '23 at 16:34

1 Answers1

3

i resolved my problem with : add the option message_bus: false in my config/packages/mailer.yaml:

framework:
  mailer:
    dsn: '%env(MAILER_DSN)%'
    message_bus: false
HAron
  • 43
  • 7