Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mariam528's avatar

php mailer

hello i am using php mailer to send mails in laravel. i need to include view file in body of php mailer and often need to pass data to view of emails. perhaps anybody know how to include view file in body of php mailer?

0 likes
5 replies
neilstee's avatar

@mariam528 you can render a blade file and put it in the mailer body like

$mail= new PHPMailer\PHPMailer();
// other configuration
$mail->IsHTML(true);
$mail->Body = view('email')->render();
$mail->Send()
1 like
neilstee's avatar
neilstee
Best Answer
Level 34

@mariam528 then pass it like usual?

$mail= new PHPMailer\PHPMailer();
// other configuration
$mail->IsHTML(true);
$mail->Body = view('email', ['data' => 'sample'])->render();
$mail->Send()
neilstee's avatar

Then in your email.blade.php will be like:

<p>This is the sample email {{ $data }}</p>

Please or to participate in this conversation.