I am new to sendgrid, and want to integrate sendgrid with Laravel. Here I tried as - Added below code in app\Mail\SendgridEmail.php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class SendgridEmail extends Mailable
{
use Queueable, SerializesModels;
public $data;
public function __construct($data)
{
$this->data = $data;
}
public function build()
{
$address = 'demotest@gmail.com';
$subject = 'This is a demo!';
$name = 'Sam';
return $this->view('emails.templateUserRegister')
->from($address, $name)
->subject($subject)
->with([ 'message' => $this->data['message'] ]);
}
}
- Created template file views/emails/templateUserRegister.blade.php as
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
</head>
<body>
<h2>Bowoot Email</h2>
<p>{{ $message }}</p>
</body>
</html>
- Added below code to controller
use App\Mail\SendgridEmail; // on top of class
public function sendemail()
{
$data = array('message' => 'This is a SendgridEmail test!');
Mail::to('user@gmail.com')->send(new SendgridEmail($data));
}
and when I run the code I found the error message as below
(2/2) ErrorException htmlspecialchars() expects parameter 1 to be string, object given (View: C:\xampp\htdocs\bowoot\resources\views\emails\templateUserRegister.blade.php) in helpers.php (line 547)
I am unable to understand what the issue is. Please help.