首页 > 解决方案 > 如何在 Laravel Mailable 中启用 HTML

问题描述

我正在尝试使用可邮寄功能将 HTML 格式的文本发送到 Laravel 中的电子邮件。发送数据时,它包含 HTML 标签。

例子

Order description <p>Lorem Ipsum is simply <b> dummy text</b> of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p>

代替:

Order description Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s

发送邮件.php

public function build()
{
    return $this->from('support@example.com')
        ->to('support@example.com')
        ->subject('Premium Article Writers') 
        ->view('invoice')
        ->text('invoice')
        ->with('data',$this->data);
}

控制器

$data = [
    'description' => $request->description,
];
                       
Mail::to($sender)->send(new SendMail($data));

invoice.blade.php

{!! $data['description'] !!}

标签: phplaravel

解决方案


删除->text('invoice')此以文本格式发送的行。默认情况下它是 HTML。


推荐阅读