0
public function postForgotPassword(Request $request)
{
    if (\Auth::check() ) {
        return redirect('/');
    }

    $user = \User::where("email", $request->input('email'))->get()->first();

    $signature = (array(
        "owner_name" => "Test",
        "owner_rank" => "Super Admin"
    ));

    $data = array(
            "first_name" => $user->first_name,
            "last_name" => $user->last_name,
            "email" => $user->email,
            "link" => ******,
            "signature" => $signature
        );
        \Mail::send('email.password', $data, function($message) use ($user) {
            $message->from("admin@test.com", "Test");
            $message->to($user->email, $user->first_name." ".$user->last_name)->subject("Reset your password.");
        });

        return response()->json(["success" => true, "message" => "Check your email!"]);
    }

My email template looks like this:

<div id="email">
    <div style="width: 600px;">
        <div style="width: 300px; float: left;">
            <h3>{{ $last_name }} {{ $name }},</h3>
        </div>
   </div>
</div>

When I try to send the email I get this error:

Undefined variable: name

Any ideas why? Thank you all for your time!

aynber
  • 22,380
  • 8
  • 50
  • 63
Alphonse
  • 661
  • 1
  • 12
  • 29
  • 1
    You have first_name and last_name in your data array, but not name. – aynber Dec 08 '16 at 16:05
  • Possible duplicate of [PHP: "Notice: Undefined variable" and "Notice: Undefined index"](http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index) – Henders Dec 08 '16 at 16:06

1 Answers1

1

You should send a name parameter from the Mail::send() method like this:

It doesn't seems that you're sending a variable named - name to the mail template via $data

$data = array(
    "first_name" => $user->first_name,
    "last_name" => $user->last_name,
    "email" => $user->email,
    "link" => ******,
    "signature" => $signature,
    'name' => 'enter_name_here' // <------- Specify your name here
);

Hope this helps!

Saumya Rastogi
  • 13,159
  • 5
  • 42
  • 45