简体   繁体   English

Laravel邮件队列与邮件发送不同

[英]Laravel Mail queue different than Mail send

I'm trying to send mails using simple DB queue driver. 我正在尝试使用简单的数据库队列驱动程序发送邮件。 Queue works fine, but problem is with mail content. 队列工作正常,但邮件内容存在问题。 When I'm sending email with send() method all is fine. 当我使用send()方法发送电子邮件时,一切都很好。 Content is like it should be, but when trying to use queue, content is not as should be, I get content from 2nd line of this code (but content is changed after second line before queueing mail): 内容是应该的,但是当尝试使用队列时,内容不是应该的,我从此代码的第二行获取内容(但是在对邮件进行排队之前,第二行之后内容已更改):

        $mail->textPlain = strip_tags($request->content);
    $mail->textHtml = base64_encode($request->content);
    $mail->date = date("Y-m-d H:i:s");
    $mail->save();

    //This mail content will be sent
    $thread = $this->getThread($ticket, $request->content);
    $mail->textPlain = strip_tags($thread);
    $mail->textHtml = base64_encode($thread);

    Email::to($ticket->from)->queue(new Reply($mail));

That part where I'm appending $mail object is not shown in final message when using queues, final message is - $mail->textHtml = base64_encode($request->content); 使用队列时,我要附加$ mail对象的那部分没有显示在最终消息中,最终消息是- $mail->textHtml = base64_encode($request->content); . But should be - $thread = $this->getThread($ticket, $request->content); $mail->textPlain = strip_tags($thread); $mail->textHtml = base64_encode($thread); 但是应该是- $thread = $this->getThread($ticket, $request->content); $mail->textPlain = strip_tags($thread); $mail->textHtml = base64_encode($thread); $thread = $this->getThread($ticket, $request->content); $mail->textPlain = strip_tags($thread); $mail->textHtml = base64_encode($thread);

$mail is object from Mail model. $ mail是Mail模型中的对象。

Process: I'm storing in DB just last reply from input, but final reply message delivered to recipient is all messages in thread. 流程:我将来自输入的最后一个答复存储在DB中,但是传递给收件人的最后答复消息是线程中的所有消息。

reply.blade.php reply.blade.php

{!! base64_decode($reply->textHtml) !!}

When the job gets serialized, the Model instances aren't serialized as a representation of the current object. 序列化作业时,不会将Model实例序列化为当前对象的表示形式。 There is basically an identifier stored which is used to retrieve the Model instance from the database when the job is unserialized. 基本上存储了一个标识符,当该作业未序列化时,该标识符用于从数据库中检索Model实例。 (class type, id value to query for, loaded relationships, roughly) (类类型,要查询的ID值,已加载的关系)

Anything that isn't persisted wont be available when the model is retrieved from the database. 从数据库中检索模型时,所有未持久的内容将不可用。

Illuminate\\Queue\\SerializesModels -> Illuminate\\Queue\\SerializesAndRestoresModelIdentifiers Illuminate\\Queue\\SerializesModels > Illuminate\\Queue\\SerializesAndRestoresModelIdentifiers

If you need other information, you can have more variables passed to the Job when created. 如果需要其他信息,可以在创建作业时将更多变量传递给作业。

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

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