Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
167 views
in Technique[技术] by (71.8m points)

forms - Make a redirection to homepage after message send with PHP

I want to have a redirection (to index.php, my homepage) when the message in my contact form has been sent but I don't see how to do it so I ask your precious help.

Here is my PHP code:

<?php
$to       = "[email protected]"; 
$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" . "
";
  $headers .= "Content-type:text/html;charset=iso-8859-1" . "
";
  $headers .= "From: ".$name." <".$email.">
"."Reply-To: ".$email."
" ;
  $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.";
  }
}
?>
question from:https://stackoverflow.com/questions/65843136/make-a-redirection-to-homepage-after-message-send-with-php

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you want to redirect use header("Location: http://example.com/myOtherPage.php");. The question has already been answered How do I make a redirect in PHP? check it out .


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...