Home > Article > Backend Development > How to Redirect a User to Another Page After PHP Form Submission?
Many users have encountered difficulties redirecting users to another page after submitting a form in PHP. This issue arises when developers attempt to replace the current page's content with custom "success" HTML without considering the proper timing.
To resolve the issue, the redirect header should be added immediately after the @mail($email_to, $email_subject, $email_message, $headers); line.
<code class="php"><?php // ... @mail($email_to, $email_subject, $email_message, $headers); // Redirect to another PHP page header('Location: nextpage.php'); // ... ?></code>
This method of redirection will prevent the "Thanks for subscribing to our mailing list" message from displaying on the current page. Instead, this message should be displayed on the redirected page.
The above is the detailed content of How to Redirect a User to Another Page After PHP Form Submission?. For more information, please follow other related articles on the PHP Chinese website!