How can I use mailer-symfony extension

Hi
I was trying to run GitHub - yiisoft/mailer-symfony: Yii Framework Symfony Mailer Integration extenstion with my Yii 2.0 but I’m doing something wrong :(.

It seems that either I’m so PHP novice or I can’t read properly Yii documentation.

In mailer-sympfony documentation there is instruction to create Mailer instance like this:

$template = new MessageBodyTemplate('/path/to/directory/of/view-files');

$mailer = new Mailer(
    new MessageFactory(Message::class),
    new MessageBodyRenderer($view, $template),
    $dispatcher,
    $transport,
);

At first glance I though that this will be easy - but then realised that I don’t know how I can get $view, $dispatcher and $transport instances… I found that $view I can get by:

Yii::$app->view;

But what can I do to get remaining others?

Then I picked different approach. I thought that maybe I should get it via $config - so I tried:

        'mailer' => [
            'class' => 'Symfony\Component\Mailer\Mailer',
        ],

Now when I’m trying to send e-mail I’m getting exception:

Can not instantiate Symfony\Component\Mailer\Transport\TransportInterface.

I’ve got a feeling that I’m doing it completely wrong :(. Maybe some of you can point me to some direction - thanks! :slight_smile:

Hi @adalbertus, welcome to the forum.

The extension seems to be meant for Yii 3.0, not for Yii 2.0. That should be the cause of your issue.

Consider using yii2-swiftmailer instead.

There’s now GitHub - yiisoft/yii2-symfonymailer: Yii 2 Symfony mailer extension.. Use it and config approach that is mentioned in the readme.

1 Like

Nice! :slight_smile:
I will try it :slight_smile: - thank you!
/Wojtek