4

I have created a mailable php artisan make:mail SendInEmail

class SendInEmail extends Mailable
{
    use Queueable, SerializesModels;

    public $email;
    public $sub;
    public $emailcontent;

    /**
     * Create a new message instance.
     *
     * @return void
     */

    public function __construct($email, $sub, $emailcontent)
    {
        $this->email = $email;
        $this->sub = $sub;
        $this->emailcontent = $emailcontent;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
         return $this->subject($sub)->view('emails.sendemail');
    }
}

In the build function I am passing the $sub variable, which comes from the controller, but it gives me an error:

Undefined variable: sub

When I use this:

 return $this->subject('Some subject')->view('emails.sendemail');

It works fine.

P.S I did some research and found that I need use function to pass the subject variable (some anonymous function magic) (Not sure how to do that with mailables)

1 Answer 1

8

You're using the wrong variable, so change it to $this->sub:

return $this->subject($this->sub)->view('emails.sendemail');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.