在laravel 4中提交表单后重定向到联系人页面

时间:2013-07-27 14:30:08

标签: php laravel laravel-4 sendmail

我想在提交详细信息后重定向回联系人页面。我已经看过论坛的解决方案,但我无法找到解决方案。

到目前为止,这就是我所拥有的:

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

这会将结果正确地发送到指定的电子邮件地址,但仍保留在“/ sendmail”页面上。

1 个答案:

答案 0 :(得分:4)

你试过了吗?

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