Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Mailer] AbstractTransport silently doing nothing if no recipients set #35805

Closed
@jschaedl

Description

@jschaedl

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.

https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Mailer/Transport/AbstractTransport.php#L68

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions