简体   繁体   English

Laravel电子邮件功能-REST API

[英]Laravel Email Function - REST API

Quick Fire Question, I am using mail function of laravel 5.1, but it still gives me variable not defined error, I have debugged and checked the variable I am printing is valid. 快速解答问题,我正在使用laravel 5.1的邮件功能,但是它仍然给我变量未定义的错误,我已经调试并检查了我正在打印的变量是否有效。

$email_id = $users[0]['email_id'];
//i have checked $email_id by printing and it is working.

    Mail::send('emails.forgetpassword', ['title' => $title, 'name' => $name, 'content' => $content, 'link' => $link], function ($message)
                    {
                        $message->from('xyz@gmail.com', 'xyz Team');
                        $message->to($email_id);
                        $message->subject('xyz App - Forget Password');
                    });

I have checked the documentation I don't know what it is missing. 我检查了文档,但不知道缺少了什么。 It throws me error at this line 这条线让我出错

$message->to($email_id);

I don't know why $email_id is already defined and working. 我不知道为什么$ email_id已经定义并且可以工作。

$email_id = $users[0]['email_id'];
//i have checked $email_id by printing and it is working.

Mail::send('emails.forgetpassword', 
    [
       'title' => $title, 
       'name' => $name, 
       'content' => $content, 
       'link' => $link
    ], 
    function ($message) use($email_id) {
         $message->from('xyz@gmail.com', 'xyz Team');
         $message->to($email_id);
         $message->subject('xyz App - Forget Password');
    }
);

You need to send email_id to anonymous function. 您需要将email_id发送给匿名函数。 it is undefined in anonymous function's scope 在匿名函数的作用域中未定义

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM