首页 > 解决方案 > 使用 PHP 发送消息后重定向到主页

问题描述

index.php当我的联系表单中的消息已发送但我不知道该怎么做时,我想重定向(到我的主页),所以我请求您的宝贵帮助。

这是我的PHP代码:

<?php
$to       = "test@test.me"; 
$name     = $_REQUEST["name"];
$email    = $_REQUEST["email"];
$subject  = $_REQUEST["subject"];
$msg      = $_REQUEST["message"];

if (isset($email) && isset($name)) {
     
  $website = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; 
  $headers = "MIME-Version: 1.0" . "\r\n";
  $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
  $headers .= "From: ".$name." <".$email.">\r\n"."Reply-To: ".$email."\r\n" ;
  $msg     = "Bonjour Anne-Valérie, <br/> <br/> vous avez un nouveau message de $name ($email)<br/><br/>Message: $msg <br><br> -- <br>Cet email a été envoyé depuis $website";
    
  $mail =  mail($to, $subject, $msg, $headers);
  if($mail)
  {
    echo 'Votre mail a bien été envoyé, une réponse vous sera apporté sous peu, merci de votre confiance.';
  }

  else
  {
    echo "Oups, quelque chose n'a pas fonctionné, veuillez vérifier vos informations.";
  }
}
?>

标签: phpformsredirect

解决方案


如果你想重定向使用header("Location: http://example.com/myOtherPage.php");. 这个问题已经回答了如何在 PHP 中进行重定向?一探究竟 。


推荐阅读