简体   繁体   English

使用队列时Laravel邮件不起作用

[英]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. 我已经在laravel中工作了几个月了,但是我决定现在应该将它们放入队列中,而不是减慢用户页面加载的时间。

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 local.ERROR:/ Applications / MAMP / htdocs / tp / vendor / laravel / framework / src /中的异常'Symfony \\ Component \\ Debug \\ Exception \\ FatalErrorException'和消息'Method Swift_Message :: __ toString()不得抛出异常'照亮/邮件/运输/MailgunTransport.php:0

If i switch back to sync driver, everything works again. 如果我切换回sync驱动程序,一切都会再次起作用。

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): 包含的new_team电子邮件(管理员是我的路线之一):

@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. 事实证明问题出在基本电子邮件的img标签中使用了asset()

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

becomes <img alt="tp" src="{{$message->embed('http://tp.co/img/tp.jpg')}}"> 成为<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. 这不是理想的选择,因此,如果有人知道如何在排队的电子邮件中执行相对路径,请告诉我,我将接受该答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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