【问题标题】:Make a redirection to homepage after message send with PHP使用 PHP 发送消息后重定向到主页
【发布时间】:2021-01-22 10:10:15
【问题描述】:

当我的联系表单中的消息已发送但我不知道该怎么做时,我想要重定向(到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.";
  }
}
?>

【问题讨论】:

  • 您可以拨打header("Location:./index.php"); exit();。但是,您不能在此调用之前回显任何内容。因此,您必须先删除 echo 行...或使用其他方法对其进行管理
  • 感谢您抽出时间 Gowire。那么我必须把回声放在哪里?

标签: php forms redirect


【解决方案1】:

如果你想重定向使用header("Location: http://example.com/myOtherPage.php");。这个问题已经回答了How do I make a redirect in PHP?看看。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-30
    • 1970-01-01
    • 2015-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-14
    • 2020-11-14
    相关资源
    最近更新 更多