联系表格Laravel 4-路由问题

时间:2016-07-21 08:30:43

标签: php laravel-4

我正在尝试做这个联系表格,但我是:(

我有这样的表格:

{{ Form::open(array('url' => 'PagesController@contact', 'method' => 'POST',  'role' =>'form', 'class' =>'form-horizontal' )) }}
    <div class="form-group">
        {{ Form::label('name', 'Nombre:', ['class' => '']) }}                       
        {{ Form::text('name', '', ['class' => 'form-control', 'maxlength' => 20]) }}
    </div>

    <div class="form-group">
        {{ Form::label('email', 'Email:', ['class' => '']) }}                   
        {{ Form::email('email', '', ['class' => 'form-control']) }}
    </div>

    <div class="form-group">
        {{ Form::label('subject', 'Asunto:', ['class' => '']) }}                    
        {{ Form::text('subject', '', ['class' => 'form-control']) }}
    </div>
        <div class="form-group">    
        {{ Form::label('country', 'Pais:', ['class' => '']) }}                  
        {{ Form::text('country', '', ['class' => 'form-control']) }}
    </div>

    <div class="form-group">
        {{ Form::label('textarea', 'Message:', ['class' => '']) }}                          
        {{ Form::textarea('msg', '',  ['class' => 'form-control', 'placeholder' =>'Your Message', 'required'=>'true'])  }}
    </div>


    <div class="form-group">
        {{ Form::submit('Send', array('class' => 'btn btn-primary btn-md')) }}
    </div>


{{ Form::close() }}

在view / emails / contact.blade.php

Name:   {{ $name }}
Email:  {{ $email }}
Country:    {{ $country }}
Subject:    {{ $subject }}
Message: {{ $msg }

在我的App / Config / mail.php中:

return array(   
   'driver' = 'smtp',  
   'host' = 'smtp.gmail.com',  
   'port' = 587,  <br/> 
   'from' = array('address' = 'africamia@gmail.com', 'name' = 'Admin'),  
   'encryption' = 'tls',   
   'username' = 'africamia@gmail.com',   
   'password' = '123456',   
   'sendmail' =  '/usr/sbin/sendmail -bs',   
   'pretend' = false,  
); 

在我的Pages@Controller.php

public function contact()
{
    $validation = New ?? I don't know what I do here :(;

    if($validation->passes()) {

       $fromEmail = Input::get('email');
       $fromName = Input::get('name');
       $subject = "Email from someone at website.com";
       $data = [ 'msg' => Input::get('message') ];

       $toEmail = 'africamia83@gmail.com';
       $toName = 'Admin';

       Mail::send('emails.contact', $data, function($message) use ($toEmail, $toName, $fromEmail, $fromName, $subject){

           $message->to($toEmail, $toName);

           $message->from($fromEmail, $fromName);

           $message->subject($subject);
       });

    return Redirect::to('/gracias')
        ->with('message', 'Your message was successfully sent!');
    }

    return Redirect::back()
        ->withInput()
        ->withErrors($validation->errors);
}

在路线

Route::get('contact', array('as' =>'contact', 'uses'=> 'PagesController@contact'));

Route::get('contact', function() {

return View::make('contact');

});

我有这个错误:

当我点击n提交按钮时,在浏览器中显示:../ public / PagesController @ contact

异常处理程序出错:未为PagesController @ contact

定义Route [/]

1 个答案:

答案 0 :(得分:0)

当您提交for时,它是POST请求,而不是GET。您将其定义为GET请求。请更改路径文件,如下所示:

Route::post('contact', 'PagesController@contact');