Redirect to contacts page after submitting form in laravel 4

♀尐吖头ヾ 提交于 2021-01-27 20:02:51

问题


I would like to redirect back to the contacts page once I have submitted my details. I have looked on solutions from the forums but I cannot get a solution.

So far this is what I have:

Route::post('sendmail', function()
{
    Mail::send('emails.auth.mail', array('token'=>'SAMPLE'), function($message){
        $message = Swift_Message::newInstance();
        $email = $_POST['email']; $name = $_POST['name'];
        $message->setFrom(array($email => $name));

        $message->setTo(array('name@name.com' => 'Jim Scott')); 

        $subject = $_POST['subject'];   
        $message->setSubject($subject); 

        $msg = $_POST['msg'];   
        $message->setBody($msg);

        $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')->setUsername('username')->setPassword('pass');

        $transport->setLocalDomain('[127.0.0.1]');

        $mailer = Swift_Mailer::newInstance($transport);

        $result = $mailer->send($message);

        if($result) {
            return Redirect::to(URL::previous())->with('success', 'You have posted successfully');
        }
    });
});

This sends results to the specified email address correctly but remains on the '/sendmail' page.


回答1:


Have you tried:

return Redirect::back()->with('success', 'You have posted successfully');

?



来源:https://stackoverflow.com/questions/17898883/redirect-to-contacts-page-after-submitting-form-in-laravel-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!