【问题标题】:How to attach a Laravel blade view in mail如何在邮件中附加 Laravel 刀片视图
【发布时间】:2016-09-26 16:32:39
【问题描述】:

我正在尝试在发送邮件时附加刀片视图。我正在使用 Laravel 4。我试过这个:

Mail::send(
    "emails.clientEmail",
    $data,
    function($message) use ($data,$template,$subject) {
        $message->to($data['email'], $data['name'])
            ->from($template['from'],$template['from_name'])
            ->subject($subject)
            ->attach(app_path().'/views/email.blade.php');
    }
);

但我的观点email.blade.php 在刀片模板中,它不显示html,而是显示代码。

我应该如何发送并显示为 html?

【问题讨论】:

    标签: php laravel email laravel-4 blade


    【解决方案1】:

    正如您所提到的,您可以使用 attachData 并添加渲染数据,例如:

    $renderedData = view('email')->render();
    
    Mail::send(
            "emails.clientEail",
            $data,
            function($message) use ($data,$template,$subject) {
                $message->to($data['email'], $data['name'])
                    ->from($template['from'],$template['from_name'])
                    ->subject($subject)
                    ->attachData($renderedData, 'name_of_attachment');
            }
        );
    

    【讨论】:

    • 谢谢,我现在就试试。我应该在哪里找到 $filePath - 它应该在哪个目录中?
    • 例如/{projectPath}/ storage/tmp
    • 哦,实际上我可以发送从数据库中获取的 html 数据作为模板,而不是 ov 刀片视图。也许这是更好的解决方案,但在这种情况下我应该使用 - attachdata('my html here', 'name');
    • ...当然也可以根据需要将数据库中的数据作为$renderedData 放置
    • 我现在就试试。 :) 谢谢
    猜你喜欢
    • 2016-11-01
    • 2019-03-18
    • 2018-08-01
    • 1970-01-01
    • 2013-08-03
    • 2018-06-04
    • 2015-08-09
    • 2018-09-14
    • 2015-10-03
    相关资源
    最近更新 更多