Send blade template mail with mailgun

479 Views Asked by At

I am trying to send mail with Mailgun. If I write this:

$mg = Mailgun::create('xxxx');
        $mg->messages()->send('xxxx', [
            'from' => '[email protected]',
            'to' => '[email protected]',
            'subject' => 'Your Link To Login!',
            'text' => 'hello',
        ]);

it works but I want to send a view (blade) and I don't know how to do.

My code is:

public function build(array $customer)
{
  return view('link')->with([
    'customer'=> $customer,
  ]);
}
public function sendContactForm(array $customer)
{
  $aaa=$this->build($customer);
  $mg = Mailgun::create('xxxxxx')

  $mg->messages()->send('xxxx'), [
    'from' => $customer['customerEmail'],
    'to' => '   [email protected]',
    'subject' => 'Contact Message',
    'html' => $aaa,
  ]);
}

This does not work when I write html or text.

What should I do?

1

There are 1 best solutions below

0
On BEST ANSWER

Add ->render() to your build call to store the contents of the view as a string:

public function build(array $customer)
{
  return view('link')->with([
    'customer'=> $customer,
  ])->render();
}