将laravel 5.4文本邮件内容类型更改为text/plain [英] change laravel 5.4 text mail content-type to text/plain

查看:57
本文介绍了将laravel 5.4文本邮件内容类型更改为text/plain的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用laravel发送排队的文本邮件:

I am sending a queued text mail with laravel:

UploadController.php的一部分:

part of UploadController.php:

public function postDelete(Request $request)
{
    $upload = Upload::where('filename',$request->filename)->where('accepted',0)->delete();

    $this->image->deleteFromUploadFolder($request->filename);

    Cache::forget('waiting_uploads');

    $msg = 'upload has been deleted';
    Mail::to('aaaaa@bbbbbb.de')->queue(new TextMail($msg));

    return redirect('upload');
}

可邮寄(TextMail.php):

Mailable (TextMail.php):

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class TextMail extends Mailable
{
    use Queueable, SerializesModels;

    protected $msg;
    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($msg)
    {
        $this->msg = $msg;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->text('emails.empty')
                    ->subject($this->msg)
                    ->with('msg',$this->msg);
    }
}

视图 empty.blade.php 应该只显示以下消息:

The view empty.blade.php should only print the message:

{{ $msg }}

但是 neomutt 接收到 text/html 内容:

But neomutt receives text/html content:

[-- text/html wird nicht unterstützt ('v' benutzen, um diesen Teil anzuzeigen) --]

和雷鸟也显示text/html而不是纯文本:

and thunderbird also shows text/html instead of plain text:

MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

我该怎么办才能收到邮件,以便Neomutt不会抱怨?使用 Mail :: send()时,我得到的是 text/plain ,但没有得到 Mail :: queue().

What can I do to get the mail so that neomutt does not complain? When using Mail::send() I get text/plain but not with Mail::queue().

推荐答案

好的,从逻辑上讲. Laravel 使用 SwiftMailer .尝试这样(暂时无法检查):

Ok,just logically. Laravel uses SwiftMailer. Try like this (cann`t check for the moment):

Mail::send('emails.empty', ['msg'=>$msg], function ($message) {
    $message->to(....)
    ->subject(....)
    ->getSwiftMessage()
    ->getHeaders()
    ->setContentType('text/plain');
});

说明:在回调 $ message 中具有方法 getSwiftMessage (请参阅

Explanation: in callback $message has method getSwiftMessage ( see .../Illuminate/Mail/Message.php). Via object SwiftMessage we get access to getHeaders and setContentType by SwiftMailer's specified class ( see ../swiftmailer/source-class-Swift_Mime_SimpleMimeEntity ).

这篇关于将laravel 5.4文本邮件内容类型更改为text/plain的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆