Forum Moderators: coopster

Message Too Old, No Replies

Where do they go after they submit an email?

         

Bubzeebub

3:08 am on Oct 14, 2004 (gmt 0)

10+ Year Member



I have a contact page where visitors enter their text and click 'Submit.' The .php files do their thing and I get the email. The problem, however, is that after the user clicks 'Submit' they are then taken to a blank page where they are instructed to press the 'Back' button on their browser. This isn't good enough. Is there a way in which the user can be redirected to the homepage after they click Submit?

Cook

3:29 am on Oct 14, 2004 (gmt 0)

10+ Year Member



Hi Bubzeebub,

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

dreamcatcher

8:47 am on Oct 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



An alternative is a meta refresh.


function redirect()
{
echo "Thank you....please wait...";
echo "<meta http-equiv=\"refresh\" content=\"4;URL=whatever.php\">\n";
exit;
}

after your form is processed, call the function:

redirect();

Bubzeebub

9:01 pm on Oct 15, 2004 (gmt 0)

10+ Year Member



One more question...where in the mail.php file should I put the line:

header('location: ['...] . $_SERVER['SERVER_NAME'] . '/path_to/the_page.html');

Bubzeebub

9:13 pm on Oct 15, 2004 (gmt 0)

10+ Year Member



or is it the confirm.php file I have to edit?

Bubzeebub

9:48 pm on Oct 15, 2004 (gmt 0)

10+ Year Member



Below is my confirm.php file. Can anyone see where I could be going wrong here?

<html>
<head>
<title>Untitled</title>

</head>

<body>

Your mail has been sent. <br>

<br>

Click the 'Back' button on your browser to return to the homepage.

<?

?>

</body>
</html>

kumarsena

10:08 pm on Oct 15, 2004 (gmt 0)

10+ Year Member



make this your comfirm.php page content:

<?
echo 'Your mail has been sent.';
header('location: ['...] . $_SERVER['SERVER_NAME'] . '/path_to/the_page.html');

?>

it shoul work

Bubzeebub

10:46 pm on Oct 15, 2004 (gmt 0)

10+ Year Member



Thanks for your reply!

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?

Bubzeebub

10:47 pm on Oct 15, 2004 (gmt 0)

10+ Year Member



Thanks for your reply!

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?

kumarsena

11:15 pm on Oct 15, 2004 (gmt 0)

10+ Year Member



try this,,,
replace

['...] . $_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...]

Birdman

11:23 pm on Oct 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<?
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

Bubzeebub

11:55 pm on Oct 15, 2004 (gmt 0)

10+ Year Member



Thank you both for responding....

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?

Birdman

12:12 am on Oct 16, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ok! That helps. The mail script is just include()ing the confirm page. So you never leave mail.php. It's not possible to redirect from confirm.php in this way because, once again, text has already been sent to the browser. Once it hits <html> in the mail script, it's too late to redirect with headers.

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!

Bubzeebub

12:40 am on Oct 16, 2004 (gmt 0)

10+ Year Member



Birdman...YOU ROCK! It worked like a charm. Thanks again!