Reputation: 11702
I have a php page for submitting resumes. once they click submit they info all posts to mail.php
once the mail is sent i would like the user to go back to a different page on the website (where the job opportunity are located)
is is there any sort of command i can use to redirect to a different page after the mail.php is done with its business??
Thanks
Upvotes: 3
Views: 11188
Reputation: 91193
On a related note, one important thing about the PHP header command, you must make sure that you run this command BEFORE any content is displayed on that page you are running it on, or else it will not work.
For example, this will NOT work:
<html>
<head>
</head>
<body>
Hello world
</body>
<?php header("Location: mypage.php"); ?>
</html>
but this will work:
<?php header("Location: mypage.php"); ?>
<html>
<head>
</head>
<body>
Hello world
</body>
</html>
Basically, the header command will only ever work if it is used in the PHP script BEFORE any static content or even HTML tags are spit out of the script.
Upvotes: 1
Reputation: 13003
At the end of mail.php just add
header("Location: anotherpage.php");
Remember that you can't output anything before the header() call for the redirect to work properly.
Upvotes: 2
Reputation: 9480
use header() function:
header('Location: http://example.com/new_loc/');
or
header('Location: /new_loc/'); // if it's within the same domain.
Upvotes: 2
Reputation: 72510
This is a standard redirection in PHP:
<?php
header( 'HTTP/1.1 301 Moved Permanently' );
header( 'Location: http://www.example.com' );
exit;
?>
However, in your case the 301 redirection line is probably not necessary. It should be noted that the exit
is necessary, otherwise the rest of your PHP script will be executed, which you may not want (e.g. you may want to display something if there is an error).
Also, the header
function must be called before any output is sent to the browser (including blank lines). If you're unable to avoid some blank lines, put ob_start();
at the start of the script.
Upvotes: 8