0
votes

I am trying to send email using Laravel default Mail facade:-

Mail::to($user->email)->send(New NotifyUserExpiring($diff,$Sub->user));

In Mail\NotifyUserExpiring :-

<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class NotifyUserExpiring extends Mailable
{
    use Queueable, SerializesModels;

    /**
     * Create a new message instance.
     *
     * @return void
     */
     protected $user;
     protected $diff;
    public function __construct($diff,$user)
    {
        $this->user = $user;
        $this->diff = $diff;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this->view('web.mail.NotifyUserExpiring')->with('user',$this->user)->with('diff',$this->diff);
    }
}

And in web.mail.NotifyUserExpiring View file i am using the blade way of printing variable :-

Hello {{ $user->first_name }}
Message Here

When i check my mail inbox , i am reciving email with exact {{ $user->first_name }}

Hello {{ $user->first_name }} Message Here I am expecting that when i insert {{ $user->first_name }} in mail view file , it should return user first name.

<div>
    Hello {{ $user->first_name }}

    Message body test
</div>
1
Add the code of your web.mail.NotifyUserExpiring view. The problem seems to be the way you are rendering the data. - Kenny Horna

1 Answers

5
votes

Make sure your mail view file name is suffixed as .blade.php so that it goes through the Blade rendering engine.