Forum Moderators: coopster
When the php files do their thing as you say, they should as a last job, after having processed the submitted data, redirect the users to the page of your choice (eg home page) with something like:
header('location: ['...] . $_SERVER['SERVER_NAME'] . '/path_to/the_page.html');
Cheers,
Cook
header('location: ['...] . $_SERVER['SERVER_NAME'] . '/path_to/the_page.html');
<?
echo 'Your mail has been sent.';
header('location: ['...] . $_SERVER['SERVER_NAME'] . '/path_to/the_page.html');
?>
it shoul work
HOWEVER, now it just says "The Page could not be found" Here is what my confirm.php file looks like now:
<html>
<head>
<title>Confirmation</title>
</head>
<body>
<br>
<?
echo 'Your mail has been sent.';
header('location: ['...] . $_SERVER['SERVER_NAME'] . '/path_to/index.html');
?>
</body>
</html>
What could be wrong?
HOWEVER, now it just says "The Page could not be found" Here is what my confirm.php file looks like now:
<html>
<head>
<title>Confirmation</title>
</head>
<body>
<br>
<?
echo 'Your mail has been sent.';
header('location: ['...] . $_SERVER['SERVER_NAME'] . '/path_to/index.html');
?>
</body>
</html>
What could be wrong?
['...] . $_SERVER['SERVER_NAME'] . '/path_to/index.html
with the full address to the index.html,
something like [mysite.com...]
remember one space just after location:
like this
'location: [mysite.com...]
<?
echo 'Your mail has been sent.';
header('location: ['...] . $_SERVER['SERVER_NAME'] . '/path_to/the_page.html');?>
Hello, you'll have to remove the "echo" line in that example. You can't send headers after you have sent text to the browser.
Better yet, look in mail.php. I'll bet there already is a header() redirect in there. It will be below the mail() function. Simply change the URL in it accordingly.
Regards,
Birdman
My mail.php file is shown below:
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
/*set the following value below - $to = your email address.
everything else here you can leave as is, just open up confirm.php
and set the page you wish to direct people to after the mail has been sent
if you wish to change it to something other than index.php*/
$to = 'deleted@yahoo.com'; //Address mail is to be sent to
$from = 'deleted@yahoo.com'; //Sets the senders mail address
$subject = $_REQUEST['subject']; //Sets the subject from the mail form
$confirm = 'confirm.php'; //Sets the page to direct to if the mail is sent
$error = 'mailerror.php'; //Sets the page to direct to if the mail is unsent
// Don't touch anything else //
$mailheader = "";
$mailheader .= "";
if (isset($HTTP_POST_VARS)){
$mailbody = '';
while (list($key, $value) = each($HTTP_POST_VARS))
{
$mailbody .= $key . ' = ' . $value . "\r\n";
}
}
$mailforms = mail($to, $subject, $mailbody, $mailheader);
if($mailforms)
{
include("$confirm");
}
else
{
include("$error");
}
?>
</body>
</html>
Also, in regards to the confirm.php I made the change and took out the line as Birdman suggested. It now reads like this:
<html>
<head>
<title>Confirmation</title>
</head>
<body>
<br>
<?
header('location: ['...] . $_SERVER['SERVER_NAME'] . 'http://www.mysite.com/path_to/index.html');
?>
</body>
</html>
When I click the 'Submit' button to test this I still get 'Page could not be found' so I'm assuming somewhere the code is incorrect. I just can't spot it. Can you?
Here's a really easy solution. Take out all the HTML in the mail script and then redirect with header() after the mail was sent.
Notice below that no data is sent to the browser, just internal processing. Also note that in the if/else at the bottom, I replaced include() with header().
<?php
$to = 'deleted@yahoo.com'; //Address mail is to be sent to
$from = 'deleted@yahoo.com'; //Sets the senders mail address
$subject = $_REQUEST['subject']; //Sets the subject from the mail form
$confirm = '/'; //change this value to your preferred page(it's set for homepage now)
$error = 'mailerror.php'; //Sets the page to direct to if the mail is unsent
// Don't touch anything else //
$mailheader = "";
$mailheader .= "From: you@domain.com\r\n"; //so they know who it came from
if (isset($HTTP_POST_VARS)){
$mailbody = '';
while (list($key, $value) = each($HTTP_POST_VARS))
{
$mailbody .= $key . ' = ' . $value . "\r\n";
}
}
$mailforms = mail($to, $subject, $mailbody, $mailheader);
if($mailforms)
{
header('Location: ' . $confirm);
}
else
{
include('Location: ' . $error);
}
?>
That's it, you should be in business!