0

Hi guys I have the ff codes:

<?php $name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "gogel.rob@gmail.com";
$subject = "Chick SEO Contact Form: New Email from $name";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank you!";
?>

Right now its only redirecting the page to a simple echo page with text "Thank you"

Is there anyway we can redirect the user to this URL https://recurpost.com/ once the form was submitted and the email was sent instead of sending it to echo?

  • https://stackoverflow.com/questions/768431/how-do-i-make-a-redirect-in-php – Swissa Yaakov Nov 17 '20 at 04:58
  • you can use `header('Location: http://www.example.com/');` for redirection. Also, to show the message "Thank you" on "https://recurpost.com/" you can use sesion as well. – Bhagchandani Nov 17 '20 at 05:00
  • Use php header function. – Tara Prasad Gurung Nov 17 '20 at 05:00
  • I treid this on my server but it returned this Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd1/277XX77/public_html/contact.php:1) in /storage/ssd1/277/15414277/public_html/contact.php on line 11 –  Nov 17 '20 at 05:05

2 Answers2

1

You need to use the Php header function. Instead of the echo, you can use the following:

header("Location: https://recurpost.com/");

The above code will include a "location" header in the Http response. This will cause the browser to redirect the user to the given url. See the documentation for the header function

Nadir Latif
  • 3,690
  • 1
  • 15
  • 24
  • I treid this on my server but it returned this `Warning: Cannot modify header information - headers already sent by (output started at /storage/ssd1/277XX77/public_html/contact.php:1) in /storage/ssd1/277/15414277/public_html/contact.php on line 11` –  Nov 17 '20 at 05:03
  • Well the documentation for the header function mentions: "Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP.". So your code must be sending output before the header function is called – Nadir Latif Nov 17 '20 at 05:06
  • also check header before sending with headers_sent() – Jerson Nov 17 '20 at 05:32
0

Try using

<?php
  echo "
        <script>
                window.location.replace('https://urdomain.org/successpage');
        </script>
    ";
Potato
  • 83
  • 1
  • 7