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()
    {
        // [...]
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 求购一套带接口实现实习自动签到打卡
  • ¥50 MacOS 使用虚拟机安装k8s
  • ¥500 亚马逊 COOKIE我如何才能实现 登录一个亚马逊账户 下发新 COOKIE ..我使用下发新COOKIE 导入ADS 指纹浏览器登录,我把账户密码 修改过后,原来下发新COOKIE 不会失效的方式
  • ¥20 玩游戏gpu和cpu利用率特别低,玩游戏卡顿
  • ¥25 oracle中的正则匹配
  • ¥15 关于#vscode#的问题:把软件卸载不会再出现蓝屏
  • ¥15 vimplus出现的错误
  • ¥15 usb无线网卡转typec口
  • ¥30 怎么使用AVL fire ESE软件自带的优化模式来优化设计Soot和NOx?
  • ¥15 Ubuntu20.04.4.LTS系统如何下载安装VirtualBox虚拟机?