Php 405尝试通过Laravel的路由发送电子邮件时出错
正在尝试使用Laravel发送电子邮件,但不断收到405错误和whoops页面显示:Php 405尝试通过Laravel的路由发送电子邮件时出错,php,email,laravel,laravel-4,laravel-routing,Php,Email,Laravel,Laravel 4,Laravel Routing,正在尝试使用Laravel发送电子邮件,但不断收到405错误和whoops页面显示: * @param array $others * @return void * * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException */ protected function methodNotAllowed(array $others) { throw new MethodNotA
* @param array $others
* @return void
*
* @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
*/
protected function methodNotAllowed(array $others)
{
throw new MethodNotAllowedHttpException($others);
}
代码是:
{{ Form::open(array('url' => 'admin/newemail')) }}
// form items
{{ Form::close() }}
路线是:
Route::get('admin/newemail', function()
{
$email = 'email@hotmail.com';
$data = array('s' => Input::get('email-heading'));
Mail::send('emails.wereback', $data, function($message) use ($email){
// $message details
});
});
但是,如果我直接转到url admin/newemail,它可以正常工作
是否有帮助?默认情况下,表单帮助程序将生成一个使用POST方法的html表单。如果需要使用其他方法,可以指定该方法:
{{ Form::open(array('url' => 'admin/newemail', 'method' => 'GET')) }}
或者,您也可以更改路线以匹配POST请求:
Route::post('admin/newemail', function()
{
// [...]
});
我会选择后者,这样人们就不会意外访问example.com/admin/newemail并发送电子邮件。啊,是的!我脑子里的逻辑没有正确地思考这个问题。贴子是我不需要得到的…: