【发布时间】:2016-07-21 08:30:43
【问题描述】:
我正在尝试填写此联系表,但我是:(
我有这个表格:
{{ 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() }}
在视图/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 定义路由 [/]
【问题讨论】:
-
尝试用
'action' => 'PagesController@contact'替换'url' => 'PagesController@contact' -
您在 routes.php 中定义了两次
Route::get('contact')...。您需要定义发布表单时会发生什么:Route::post('contact')...。