简体   繁体   中英

Laravel mail doesn't work when using queue

i've had email working within laravel for a few months now, but decided it's probably time to move them into a queue rather than slowing down users' page loads.

However, as soon as i switch to the database queue driver i get the following error:

local.ERROR: exception 'Symfony\\Component\\Debug\\Exception\\FatalErrorException' with message 'Method Swift_Message::__toString() must not throw an exception' in /Applications/MAMP/htdocs/tp/vendor/laravel/framework/src/Illuminate/Mail/Transport/MailgunTransport.php:0

If i switch back to sync driver, everything works again.

Could this be something to do with permissions, or different users running different jobs?

For reference the queuing is:

Mail::queue('emails.new_team', [], function($message) use ($team)
{
    $message->to('hiden@hidden.co', 'hiden');
    $message->from('hiden@hiden.co', 'hiden');
    $message->subject($team->name.' - Team Just Created!');
});

With new_team email containing (admin is one of my routes):

@extends('emails.baseemail')

@section('content')
            <h2 style="margin-bottom: 20px; font-weight: 900; font-size: 25px;">Theres a new team!!</h2>

<div style="margin: 20px 0;">
    <a href="{{ url('admin') }}">Go to Admin</a>
</div>
@stop

And Base email containing:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    @yield('specificMETA')
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
    <link rel="shortcut icon" type="image/x-icon" href="/img/favicon.ico">
</head>

<body style="font-family: 'Dosis', sans-serif; font-weight: 300; color: #666; background: #FDFDFD; margin: 0;" bgcolor="#FDFDFD">
<style type="text/css">
.button:hover {
background: #7f8c8d;
}
.cta:hover {
background: #2980b9;
}
</style>
<div id="header" style="position: inherit; z-index: 73411; font-size: 30px; line-height: 70px; color: #ecf0f1; width: 100%; height: 70px; background: #27ae60;">
        <div class="centre_col" style="width: 1024px; margin: 0 auto;">
            <div id="header_left" class="l" style="float: left;">
                <a href="/" title="Go to the xxx Homepage" class="logo" style="text-decoration: none"><img alt="tp" src="{{$message->embed(asset('img/tp.jpg'))}}"></a>
            </div>
        </div>
    </div>
    <div id="content" style="margin-top: 20px;">
        <div class="centre_col" style="width: 1024px; margin: 0 auto;">@yield('content')</div>
    </div>
</body>
</html>

It turns out the problem was using asset() within the img tag in the base email.

so <img alt="tp" src="{{$message->embed(asset('img/tp.jpg'))}}">

becomes <img alt="tp" src="{{$message->embed('http://tp.co/img/tp.jpg')}}">

So far i've just had to hard code the path to the image.

Note that it has to be the full path, so i've chosen my live server's path.

This isn't ideal, so if anyone knows how to do relative paths within queued emails, please let me know and i'll accept that answer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM