[英]change laravel 5.4 text mail content-type to text/plain
I am sending a queued text mail with laravel: 我正在使用laravel发送排队的文本邮件:
part of UploadController.php: 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');
}
Mailable (TextMail.php): 可邮寄(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);
}
}
The view empty.blade.php
should only print the message: 视图empty.blade.php
应该只显示以下消息:
{{ $msg }}
But neomutt receives text/html content: 但是neomutt接收到text / html内容:
[-- text/html wird nicht unterstützt ('v' benutzen, um diesen Teil anzuzeigen) --]
and thunderbird also shows text/html instead of plain text: 雷鸟也显示text / html而不是纯文本:
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
What can I do to get the mail so that neomutt does not complain? 我该怎么办才能收到邮件,以便Neomutt不会抱怨? When using Mail::send()
I get text/plain
but not with Mail::queue()
. 当使用Mail::send()
我得到text/plain
但没有使用Mail::queue()
。
Ok,just logically. 好的,从逻辑上讲。 Laravel
uses SwiftMailer
. Laravel
使用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');
});
Explanation: in callback $message
has method getSwiftMessage
( see .../Illuminate/Mail/Message.php ). 说明:在回调$message
有方法getSwiftMessage
(请参阅... / 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 ). 通过对象SwiftMessage
我们可以通过SwiftMailer's
指定类访问getHeaders
和setContentType
(请参见../swiftmailer/source-class-Swift_Mime_SimpleMimeEntity )。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.