laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.51k stars 11.02k forks source link

[5.3] Mail broken after upgrade #15335

Closed ClaraLeigh closed 8 years ago

ClaraLeigh commented 8 years ago

After upgrading to laravel 5.3 all outgoing mail stopped working. I couldn't see anything in the upgrade docs about this type of thing, so I'm guessing something else is going on.

I initially wanted to try out notifications, which is why I performed the upgrade in the first place. After the upgrade I tried doing a simple test email notification with the default auto generated notification file.

My route code is as follows:

Route::get('mytest', function () {
        $user = \App\Models\User::all()->first();
        $website = \App\Models\Website::all()->first();
        $user->notify(new \App\Notifications\WebsitePublished($website));
        dd('should have worked, maybe...');
    });

I have also tried sending via Mail::raw, Mail::to and also I tried changing the mail configuration to use a different driver (SMTP and Mailgun). Nothing works but if I change drivers the error message changes but only slightly.

After playing around with it I realised that while the error stack looks different for both drivers, the underlying cause is from this bit of code(in the vendor file), which varies only slightly depending on the driver used:

1:        call_user_func_array(
2:            array($this, 'Swift_Mime_SimpleMessage::__construct'),
3:            Swift_DependencyContainer::getInstance()
4:                ->createDependenciesFor('mime.message')
5:            );

If I dump and die the 3rd and 4th line of this snippet inside the vendor file, I get an empty array. This is obviously where the issue is coming from in both instances but I'm not quite familiar with the whole inner workings to figure out why it is returning empty.

Has anyone experienced this issue before or does anyone know why this may be happening?

FYI the actual error stack when trying to email via Mailgun is:

FatalThrowableError in SimpleMessage.php line 27:
Type error: Argument 1 passed to Swift_Mime_SimpleMessage::__construct() must be an instance of Swift_Mime_HeaderSet, none given, called in /home/centos/local_01/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Message.php on line 50
in SimpleMessage.php line 27
at Swift_Mime_SimpleMessage->__construct() in Message.php line 50
at Swift_Message->__construct() in Mailer.php line 409
at Mailer->createMessage() in Mailer.php line 181
at Mailer->send('emails.reminder', array('connection' => null, 'queue' => null, 'delay' => null), object(Closure)) in Mailable.php line 116
at Mailable->send(object(Mailer)) in Mailer.php line 173
at Mailer->send(object(TestMail)) in MailableMailer.php line 99
at MailableMailer->send(object(TestMail)) in web.php line 73
at RouteServiceProvider->{closure}() in Route.php line 176
at Route->runCallable() in Route.php line 147
at Route->run(object(Request)) in Router.php line 642
at Router->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Authenticate.php line 88
at Authenticate->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in SubstituteBindings.php line 41
at SubstituteBindings->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 33
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Router.php line 644
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 618
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Debugbar.php line 49
at Debugbar->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartupCheck.php line 100
at StartupCheck->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in DuplicateSubmissionCheck.php line 27
at DuplicateSubmissionCheck->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 64
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 33
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 52
themsaid commented 8 years ago

Been sending emails using 5.3 for a while now using several drivers, I don't think the issue is related to laravel, maybe some package you're using is overriding the behaviour of Swift mailer?

Can you regenerate the issue on a fresh 5.3 installation? if not then it's something related to that specific App.

ClaraLeigh commented 8 years ago

Resolved after hours of debugging :cry: In my composer.json I had autoload: { "classmap": [ 'vendor'] } Don't know why the issue didn't occur pre-laravel 5.3 but removing it fixed the problem