Lumen-framework: Target [Illuminate\Contracts\Mail\Factory] is not instantiable.

Created on 25 Mar 2020  路  19Comments  路  Source: laravel/lumen-framework


  • Lumen Version: 7.0.2
  • PHP Version: 7.3.15
  • Database Driver & Version: mysql

Description:

I am getting the following error when I run php artisan queue:work:

local.ERROR: Illuminate\Contracts\Container\BindingResolutionException: Target [Illuminate\Contracts\Mail\Factory] is not instantiable. in ....../vendor/illuminate/container/Container.php:982

in my bootstrap/app.php I added

$app->configure('mail');
$app->alias('mailer', Illuminate\Mail\Mailer::class);
$app->alias('mailer', Illuminate\Contracts\Mail\Mailer::class);
$app->alias('mailer', Illuminate\Contracts\Mail\MailQueue::class);

$app->configure('queue');

$app->register(Illuminate\Mail\MailServiceProvider::class);
$app->register(Illuminate\Queue\QueueServiceProvider::class);

This is how I try to send my mail:

Mail::to($user)->locale(App::getLocale())->send(new Register($user));

and this is the Register class:

<?php

namespace App\Mail;

use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class Register extends Mailable implements ShouldQueue
{
    use Queueable, SerializesModels;

    /**
     * The user instance.
     *
     * @var User
     */
    protected $user;

    /**
     * Create a new message instance.
     *
     * @param  User $user The user instance.
     * @return void
     */
    public function __construct(User $user)
    {
        $this->user = $user;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('emails.users.register');
    }
}

Sending mails without queueing them works perfectly fine.

laravel/lumen-framework is version 7.x - illuminate/mail and illuminate/queue are both 7.3.0

Cheers ;)

bug

Most helpful comment

I been fix the issue by adding this line

$app->alias('mail.manager', Illuminate\Mail\MailManager::class);
$app->alias('mail.manager', Illuminate\Contracts\Mail\Factory::class);

All 19 comments

@Exotelis which version of the Laravel components are you running? Can you try updating to the latest versions?

$app->configure('mail');
$app->alias('mailer', Illuminate\Mail\Mailer::class);
$app->alias('mailer', Illuminate\Contracts\Mail\Mailer::class);
$app->alias('mailer', Illuminate\Contracts\Mail\MailQueue::class);

These instructions will not work in Lumen 7, only in Lumen 6. If these are from our docs, then they need correcting.

The mail component now has a manager class.

hich version of the Laravel components are you running? Can you try updating to the latest versions?

I'm using the latest versions. Updated the last time yesterday evening.

will not work in Lumen 7, only in Lumen 6. If these are from our docs, then they need correcting.

Yes just copied it from the 7.x doc. Glad to hear that it's not my fault :)

@GrahamCampbell what's the correct way to do it now?

D'no, not looked into it.

@Exotelis don't have time atm to look into this. Feel free to send in a PR to the docs if you figure things out in the meantime.

@driesvints no worries, it's not too urgent, I'm going to dig a bit deeper on the weekend.

I have got the exact same issue. However, It's not lumen but Laravel. Yesterday I upgraded from 5.8 to 7.3 and I suddenly noticed that my emails would no longer arrive. By digging through logs, I saw this issue. @Exotelis , Please update here as soon as you find something. Thank you so much in advance.

I didn't find a solution. After a while I started testing notifications with a similar result. Target [Illuminate\Contracts\Mail\Factory] is not instantiable while building [Illuminate\Notifications\Channels\MailChannel].
But this time already without running php artisan queue:work

@khan-zia Do you use Laravel? Have you created an issue in the laravel-framework repo?

hey @Exotelis, Yeah I use Laravel, I haven't created an issue yet because I was hoping I would get some solution here. However, I will create an issue with laravel-framework. Meanwhile, do update here please if you come across something.

The same issue
Target [Illuminate\\Contracts\\Mail\\Factory] is not instantiable while building [Illuminate\\Notifications\\Channels\\MailChannel]

I currently having this issue

is there a temporary solution for this?

I been fix the issue by adding this line

$app->alias('mail.manager', Illuminate\Mail\MailManager::class);
$app->alias('mail.manager', Illuminate\Contracts\Mail\Factory::class);

I been fix the issue by adding this line

$app->alias('mail.manager', Illuminate\Mail\MailManager::class);
$app->alias('mail.manager', Illuminate\Contracts\Mail\Factory::class);

Where did you add these lines? Can you explain why this fixes the issue?

I been fix the issue by adding this line

$app->alias('mail.manager', Illuminate\Mail\MailManager::class);
$app->alias('mail.manager', Illuminate\Contracts\Mail\Factory::class);

Where did you add these lines? Can you explain why this fixes the issue?

bootstrap/app.php

I been fix the issue by adding this line

$app->alias('mail.manager', Illuminate\Mail\MailManager::class);
$app->alias('mail.manager', Illuminate\Contracts\Mail\Factory::class);

Thank you, working

Thank you for confirming this @SHELA , I will check this out too. Can you also confirm @Exotelis ?

Was this page helpful?
0 / 5 - 0 ratings