douxing8323 2015-02-05 21:34
浏览 57
已采纳

405尝试使用Laravel通过路径发送电子邮件时出错

Trying to send an email using Laravel but keep getting a 405 error and the whoops page showing:

 * @param  array  $others
 * @return void
 *
 * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
 */
protected function methodNotAllowed(array $others)
{
    throw new MethodNotAllowedHttpException($others);
}

The code is:

{{ Form::open(array('url' => 'admin/newemail')) }}
  // form items
{{ Form::close() }}

And the route is:

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
    });
});

However, if I directly go to the url admin/newemail it works fine.

Any help?

  • 写回答

1条回答 默认 最新

  • dongqintong8972 2015-02-05 21:36
    关注

    By default the Form helper will generate a html form that uses the POST method. You can specify the method if you need to use a different one:

    {{ Form::open(array('url' => 'admin/newemail', 'method' => 'GET')) }}
    

    Or you could also change your route to match POST requests:

    Route::post('admin/newemail', function()
    {
        // [...]
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HC32L176调试了一个通过TIMER5+DMA驱动WS2812B
  • ¥15 三菱FX系列PLC串口指令
  • ¥15 cocos的js代码调用wx.createUseInfoButton问题!
  • ¥15 关于自相关函数法和周期图法实现对随机信号的功率谱估计的matlab程序运行的问题,请各位专家解答!
  • ¥15 Python程序,深度学习,有偿私
  • ¥15 扫描枪扫条形码出现问题
  • ¥35 poi合并多个word成一个新word,原word中横版没了.
  • ¥15 【火车头采集器】搜狐娱乐这种列表页网址,怎么采集?
  • ¥15 求MCSCANX 帮助
  • ¥15 机器学习训练相关模型