7

Just upgraded from Laravel 6 to 7, and had the error response above when submitting a contact form. I eventually found a solution that seems to work and I am submitting here to help out the next guy.

In the terminal run:

composer require illuminate/mail 

Add the following to the top of the controller file (app/Http/Controllers/Main.php in my case):

use \Illuminate\Support\Facades\Mail;

Add this to bootstrap/app.php:

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

Save and test, and it worked localhost.

If the above does not work for you, there are some other possible issues and solutions available at this link, where I must give credit to vipindasks.

https://laracasts.com/discuss/channels/lumen/lumen-52-mail-not-working

Since I am suppose to ask a question:

Do you see any problems with this solution even though the site and mailer is working now?

noviguy
  • 73
  • 1
  • 4
  • 2
    Add a back slash `$app->register(\Illuminate\Mail\MailServiceProvider::class);` – STA Jul 02 '20 at 08:51
  • For my own curiosity, why are you registering the provider there, and not in config/app.php? – Kurt Friars Jul 02 '20 at 08:55
  • @STA Done. Thank you. – noviguy Jul 02 '20 at 16:30
  • @KurtFriars I just followed the ideas presented in the other link with some trial an error, and the site now works. I like what you are suggesting, but I messed around with some thing and could not figure it out. – noviguy Jul 02 '20 at 17:19
  • Today I encountered this problem while upgrading my Laravel6 application to Laravel8, it turns out that all I have to do was `composer dump-autoload` *without* `--no-scripts` `--no-plugins` options after following official upgrade guide. No need to tweak `bootstrap/app.php`, `Illuminate\Mail\MailServiceProvider` is staying in `config/app.php`. – ernix Feb 21 '22 at 09:14

3 Answers3

5

You are simply missing a backslash. This tells the autoloader that the file you are looking for is not in the namespace your controller resides in :

$app->register(\Illuminate\Mail\MailServiceProvider::class);
STA
  • 30,729
  • 8
  • 45
  • 59
1

Run composer update hope this will help you

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 30 '22 at 10:21
0

Common mistake for me : call Mail facade inside register() method of the service provider...

It should rather be called inside its boot() method.

Franck
  • 560
  • 7
  • 20