dqol6556
2017-04-12 07:05
浏览 45
已采纳

在Laravel 5.4中获取“未定义的变量:电子邮件”

Why am I getting "Undefined variable: emails" in Laravel 5.4, but the same code is working fine in Laravel 5.2? Below is a code snipped. Don't think this matters but I'm using PHP 7.1.3.

public function send(Request $request) {
    $emails = "";

    try {
        $emails = [$request->input('to'), "john.doe@gmail.com"];

        Mail::send('email.contact', ['request' => $request], function($message) use ($request) {
            $message->from($request->input('email'), $request->input('email'));
            $message->to($emails[0], $emails[0])
                ->cc($emails[1], $emails[1])
                ->subject("Contact Us");
        });

        $response = array (
            'success' => true,
            'message' => 'Message sent.',
            $request
        );
    }
    catch(Exception $e) {
        $response = array (
            'success' => false,
            'message' => $e->getMessage(),
            $request
        );
    }
    // return Response::json( $response );
    return $response;
}

图片转代码服务由CSDN问答提供 功能建议

为什么我在Laravel 5.4中获得“未定义变量:电子邮件”,但相同的代码在Laravel 5.2中正常工作 ? 下面是一段代码剪辑。 不要认为这很重要,但我使用的是PHP 7.1.3。</ p>

  public function send(Request $ request){
 $ emails =“”; 
 \  n尝试{
 $ emails = [$ request-&gt; input('to'),“john.doe@gmail.com”]; 
 
 Mail :: send('email.contact',['request  '=&gt; $ request],函数($ message)使用($ request){
 $ message-&gt;来自($ request-&gt; input('email'),$ request-&gt; input('email'  )); 
 $ message-&gt; to($ emailils [0],$ emailils [0])
  - &gt; cc($ email [1],$ email [1])
  - &gt; subject(  “联系我们”); 
}); 
 
 $ response = array(
'成功'=&gt; true,
'消息'=&gt;'消息已发送。',
 $ request 
  ); 
} 
 catch(Exception $ e){
 $ response = array(
'success'=&gt; false,
'message'=&gt; $ e-&gt; getMessage(),
  $ request 
); 
} 
 //返回Response :: json($ response); 
返回$ response; 
} 
 </ code> </ pre> 
 </ div>

2条回答 默认 最新

相关推荐 更多相似问题