Description
Today I struggled a bit with sending an email via the Mailer class.
Here is some example code of what tried to do:
$email = (new Email())
->from('[email protected]')
->subject('Subject')
->text('Content')
;
$this->mailer->send($email);
# .env
MAILER_DSN=smtp://localhost:1025
The implementation and the mailer configuration looked fine to me, but the email was not send out. There was also no Exception that indicated what I probably did wrong.
So I debugged my code and could find this line in the AbstractTransport
.
As you can see the AbstractTransport::send()
method is just returning null
in case there are no recipients set, which means the transport is failing "silently" without sending the email. Ok, my bad, I forgot to set a recipient. Problem solved.
But I was wondering, if this is intended behaviour? I actually would have expected an Exception telling me that I forgot to set a recipient.