2

i have this code for sending mail from Laravel.This code is perfectly running well.

Mail::send('emails.auth.accept', array(), function($message) {
                        $message->to('[email protected]', 'abc')->subject('This is a demo!');
                    });

But i can only be able to send the message using hardcode values such as [email protected].

Whenever I try this.

 Mail::send('emails.auth.accept', array(), function($message) {
                        $message->to($user, $name)->subject('This is a demo!');
                    });

Above code is giving me error : Undefined variable: user. That means it is not accepting dynamic values. help me.

2 Answers 2

4

You should use

//see use statement
Mail::send('emails.auth.accept', array(), function($message) use($user, $anything) {
  $message->to('[email protected]', 'abc')->subject('This is a demo!');
});

The problem with your code is that the anonymous function has its own context in which your data is not available. That's why you need to make use of use statement to pass data from context of your method to anonymous function.

For further information you can check this link http://php.net/manual/en/functions.anonymous.php

Sign up to request clarification or add additional context in comments.

Comments

0

You want to use. Here is a link that provides an example.

http://forumsarchive.laravel.io/viewtopic.php?id=8264

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.