我正在发送带有laravel的排队文本邮件:
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):
<?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
应该只打印消息:
{{ $msg }}
但neomutt接收文字/ HTML内容:
[-- text/html wird nicht unterstützt ('v' benutzen, um diesen Teil anzuzeigen) --]
和thunderbird也显示text / html而不是纯文本:
MIME-Version: 1.0
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable
我该怎样做才能收到邮件,以便neomutt不抱怨?
使用Mail::send()
时,我获得了text/plain
但未使用Mail::queue()
。
答案 0 :(得分:1)
好的,只是逻辑上。 Laravel
使用SwiftMailer
。试试这样(暂时不要检查):
Mail::send('emails.empty', ['msg'=>$msg], function ($message) {
$message->to(....)
->subject(....)
->getSwiftMessage()
->getHeaders()
->setContentType('text/plain');
});
说明:在回调$message
中有方法getSwiftMessage
(请参阅.../Illuminate/Mail/Message.php)。通过对象SwiftMessage
,我们可以通过getHeaders
指定的类访问setContentType
和SwiftMailer's
。(请参阅../swiftmailer/source-class-Swift_Mime_SimpleMimeEntity)。