local.ERROR:exception' ErrorException'消息'未定义变量

时间:2018-04-25 14:21:52

标签: php html laravel

尝试修复此联系表单。

最初没有发送消息部分。

现在返回 - local.ERROR:exception' ErrorException'与消息'未定义变量:内容'

联系表格:

<div class="row">
                    <div class="col-md-12">
                        <div class="form-group">
                            <textarea class="form-control textarea" rows="7" name="content" id="content" placeholder="Your Message">{{ Input::old('content') }}</textarea>
                            <span class="error">{{ $errors->first('content') }}</span>
                        </div>
                    </div>
                </div>

的PageController:

function postContactForm(Request $request){
        $rules = [
            'name'          => 'required',
            'email'         => 'required|email',
            // 'subject'            => 'required',
            'content'       => 'required',
            'g-recaptcha-response' => 'required|captcha',
            'phone' => 'numeric',
        ];
        $validator = Validator::make($request->all(), $rules);

        $toDetails = array(
                    'toName'=> '',
                    'toEmail'=> setting('email'),
                    'fromName'=> $request->input('name'),
                    'fromEmail'=> $request->input('email'),
                    );
        if($validator->passes()) {
            // ($email_template,$from_email,$email_content,$from_name,$from_phone,$toDetails)
            sendEmail('emails.contact',$request->input('email'),$request->input('content'),$request->input('name'),$request->input('phone'),$toDetails);
            Log::info($request->input('name').'<'.$request->input('email').'>'.'sent a message');
            return redirect()->back()->with('msg', 'Message sent Successfully');
        } else {
            Log::info($request->input('name').'<'.$request->input('email').'>'.' tried to send a message with the following info: '.json_encode($request->all()).' but there were errors');
            return redirect()->back()->withInput($request->all())->withErrors($validator);
        }
    }

电子邮件模板:

<!DOCTYPE html>
<html>
<body>
<h5>Email Notification from website</h5>
<p>Contact Name: <span>{{ $name }}</span></p>
<p>Email: <span>{{ $email }}</span></p>
<p>Phone: <span>{{ $phone }}</span></p>
<hr>
<p>Message:</p>
<p><span>{{ $content }}</span></p>
</body>
</html>

任何帮助都会受到很大的帮助

1 个答案:

答案 0 :(得分:0)

你不应该检查$ errors是否有'content'?

@if($errors->has('content'))
    <span class="error">{{ $errors->first('content') }}</span>
@endif

而不是

<span class="error">{{ $errors->first('content') }}</span>