问题
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