简体   繁体   中英

How to attach a Laravel blade view in mail

I'm trying to attach a blade view when send mail. I'm using Laravel 4. I tried with this:

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');
    }
);

But my view email.blade.php is in blade template and it doesn't display the html but code.

How should I send it and display as html?

As you metioned you can use attachData and add rendered data like:

$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');
        }
    );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM