I am working on my first Symfony 5 project and struggle to send mail using the build in MailerInterface
. I have worked with Swift Mailer in Symfony 3 before and never had similar issues before.
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Mailer\MailerInterface;
...
class SomeController extends AbstractController {
public someAction(Request $request, MailerInterface $mailer) {
...
$email = (new TemplatedEmail())
->from(new Address('address@example.com', 'My Symfony Mail'))
//->to($user->getEmail())
->to('receiver@example.com')
->subject('Subject')
->htmlTemplate('email.html.twig');
$mailer->send($email);
}
}
// .env
#MAILER_DSN=smtp://user:pass@smtp.example.com:25
MAILER_DSN=sendmail://default
If MAILER_DSN
has some malformed format an exception is thrown and shown on the Symfony debugger page, e.g. The "invaliddsn" mailer DSN must contain a scheme
... Thus it seems that the configured DSN smtp://user:pass@smtp.example.com:25
is correct. Using the same credentials, host and port in other mail applications is no problem.
However, when using this code no error/exception is shown and I receive no mail at all. Of course I have double checked the logs (no errors), the receivers spam folder (nothing). Specifying an SMTP server or sendmail does not make any difference.
The Symfony docs only explain how to handle exceptions but in my case no exceptions are thrown.
While there are a lot of other questions about mailing issues in Symfony, most of them deal with the older Swift Mailer or other, specific problems.
How can I figure out if a mail is send and not received or not send at all?