0
votes

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?

1

1 Answers

4
votes

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