Framework: Target [Illuminate\Contracts\Mail\Factory] is not instantiable.

Created on 31 Mar 2020  路  6Comments  路  Source: laravel/framework


  • Laravel Version: 7.3.0
  • PHP Version: 7.4.3
  • Database Driver & Version: MySql v8.x

Description:

I updated from Larvel 5.8 to 7.3 and then suddenly I noticed that my emails were no longer arriving. Mails are queued and the queue driver is the default database. By digging through the logs, I found that the IlluminateContractsMailFactory class is not instantiable and the log file for that day had more than 100 times content than usual meaning a huge internal logging spike from the updated version.

Furthermore, I also checked the jobs table in my DB and I saw that the maximum (255) attempts were all being exhausted for each mail and hence that would also explain the unprecedented amount of text in my logs that literally slowed down my machine while viewing.

Steps To Reproduce:

  • Update to Laravel's mentioned version.
  • Have some emails on queues. Preferably, trigger an event that would put an email on queue and then have something like supervisor run the queues automatically or you can also simply do php artisan queue:work
needs more info

Most helpful comment

Solution

  • This issues seems to be resolved by default in Laravel 7.4, I upgraded to 7.4 and the queued mails are working as expected,
  • With version 7.3, or if the issue is still there, add the following lines to bootstrap/app.php thanks to lloricode that has also created a PR for the lumen framework that was merged.
$app->alias('mail.manager', Illuminate\Mail\MailManager::class);
$app->alias('mail.manager', Illuminate\Contracts\Mail\Factory::class);

All 6 comments

I see there's the exact same issue that has been labeled as bug with the lumen framework as well. see #1057

Did you read the upgrade guide and the part of the new mailer config? https://laravel.com/docs/7.x/upgrade

Did you update the config file? And the new MAIL_MAILER env variable?

Did you read the upgrade guide and the part of the new mailer config? https://laravel.com/docs/7.x/upgrade

Did you update the config file? And the new MAIL_MAILER env variable?

With likelihood of impact set to optional and quoting these lines from the docs,
"In order to support multiple mailers, the default mail configuration file has changed in Laravel 7.x to include an array of mailers. However, in order to preserve backwards compatibility, the Laravel 6.x format of this configuration file is still supported. So, no changes are required when upgrading to Laravel 7.x; however, you may wish to examine the new mail configuration file structure and update your file to reflect the changes",
No, I did not bother making any changes for mailer config. However, I will go through this and if this solves the issue, I will update the thread here and will also close the issue.
Thanks for pointing this out.

Solution

  • This issues seems to be resolved by default in Laravel 7.4, I upgraded to 7.4 and the queued mails are working as expected,
  • With version 7.3, or if the issue is still there, add the following lines to bootstrap/app.php thanks to lloricode that has also created a PR for the lumen framework that was merged.
$app->alias('mail.manager', Illuminate\Mail\MailManager::class);
$app->alias('mail.manager', Illuminate\Contracts\Mail\Factory::class);

Thank khan-zia

Thanks to you khan-zia

Was this page helpful?
0 / 5 - 0 ratings