简体   繁体   English

联系表格Laravel 5.4

[英]Contact Form Laravel 5.4

I'm trying to build contact form in Laravel 5.4. 我正在尝试在Laravel 5.4中建立联系表格。 I'm almost succeeded but besides actual message, on my mail i'm getting the structure of the page (look screenshot). 我几乎成功了,但是除了实际的消息外,在我的邮件中,我还获得了页面的结构(请看截图)。 Can you help me with that? 你能帮我吗? enter image description here 在此处输入图片说明

my View Form: 我的查看表格:

                <div class="row">

      {{ Form:: open(array('action' => 'ContactController@getContactUsForm')) }}

      <ul class="errors">
      @foreach($errors->all('<li>:message</li>') as $message)
      {{ $message }}
      @endforeach
      </ul>

      <div class="form-group">
      {{ Form:: textarea ('message', '', array('placeholder' => 'Message', 'class' => 'form-control', 'id' => 'message', 'rows' => '7' )) }}
      </div>




      <div class="modal-footer">
      {{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}
      {{ Form:: close() }}


      </div>
            </div>

And my Controller: 而我的控制器:

namespace App\Http\Controllers;
use Input;
use Illuminate\Http\Request;
use Validator;
use Mail;
use Redirect;

class ContactController extends Controller
{
public function getContactUsForm(Request $request){
    //Get all the data and store it inside Store Varible
    $data = \Input::all();
    //$data = $request->message;
    //$data = $request->input('message');

    //Validation rules
    $rules = array (
        //'first_name' => 'required', uncomment if you want to grab this field
        //'email' => 'required|email',  uncomment if you want to grab this field
        'message' => 'required|min:5'
    );

    //Validate data
    $validator = Validator::make ($data, $rules);

    //If everything is correct than run passes.
    if ($validator -> passes()){



     Mail::send('support/contact', $data, function($message) use ($data)
            {
                //$message->from($data['email'] , $data['first_name']); uncomment if using first name and email fields
                $message->from('masha@mail.com', 'contact form');
    //email 'To' field: cahnge this to emails that you want to be notified.
    $message->to('masha@mail.com', 'Masha')->subject('Contact Form');

            });
            // Redirect to page
   return Redirect::route('contact')
    ->with('message', 'Your message has been sent. Thank You!');


            //return View::make('contact');
         }else{
   //return contact form with errors
            return Redirect::route('contact')
             ->with('error', 'Feedback must contain more than 5 characters. Try Again.');

     }
 }
}

change this: 改变这个:

<div class="modal-footer">
  {{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}
  {{ Form:: close() }}
</div>

To this: 对此:

<div class="modal-footer">
  {{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}
</div>
{{ Form:: close() }}

I think ordering break the structure. 我认为订购会破坏结构。

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

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