FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Help with PHP contact form





mtorregiani
Hello,

I have the following code:

Code:
<?php
if(isset($_POST['submit'])) {

$to = "mail@domain.com";
$subject = "Subject";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
 
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
 
echo "Data has been submitted to $to!";
mail($to, $subject, $body);

} else {

echo "blarg!";

}
?>


Instead of displaying "Data has been submitted to $to!", I'd like this script to go to a different page (thank_you.php).
How can I do this?
jmraker
This is what I use

Code:
function location($url){
   session_write_close();
   if(headers_sent($file, $line)){
      echo '<h1>This page will redirect <a href="' . $url . '">here</a></h1><small><i>Headers sent(' . $file . ', ' . $line . ')</i></small>';
      echo '<meta http-equiv="refresh" content="30;url=' . $url . '" />';
   }
   else
      header('Location: ' . $url);
   exit(0);
}


and you can use
Code:
location('thank_you.php');


If there's an error or something on the page it'll redirect in 30 seconds, enough time to do a select A and copy the error to the clipboard
mtorregiani
Great!
But where should I add the code that you posted?

I don't know a thing of php, sorry.

Thanks
sonam
mtorregiani wrote:
Hello,

I have the following code:

Code:
<?php
if(isset($_POST['submit'])) {

$to = "mail@domain.com";
$subject = "Subject";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];
 
$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";
 
echo "Data has been submitted to $to!";
mail($to, $subject, $body);

} else {

echo "blarg!";

}
?>


Instead of displaying "Data has been submitted to $to!", I'd like this script to go to a different page (thank_you.php).
How can I do this?


This script is too simple and I don't think it is usefull for real site. On http://www.frihost.com/users/sonam/blog/vp-83950.html I am post one simple mail form with spam protection.

Sonam
mtorregiani
Well, that's even better.
Thank you sonam! I'll post in your blog if I have any problem.
sonam
mtorregiani wrote:
Well, that's even better.
Thank you sonam! I'll post in your blog if I have any problem.


Better post here I am not check blog too often.

Sonam
DeltaM
Use a header, like a
Code:
location('thank_you.php');
Ohhh the question had already been answred hehe Very Happy
Albio
Maybe I cant understand smth., but according to php tutoriall I use the next script. And it works.
Code:
<script>
    alert( "<?php echo _THANK_MESSAGE; ?>" );
    document.location.href='<?php echo sefRelToAbs( "index.php?option=$option&amp;Itemid=$Itemid" ); ?>';
    </script>
and change it to this:


Code:
<script>
    //alert( "<?php echo _THANK_MESSAGE; ?>" );
    document.location.href='<?php echo sefRelToAbs( "your thank you url comes here" ); ?>';
    </script>
frenzy
You can get the code from php form. And all you need to do just insert it to your page.
cemycc
There are 3 types for redirect :
- javascript redirect
- html
- php header redirect http://www.php.net/manual/en/function.header.php


Also in PECL there is a nice function for redirect: http://www.php.net/manual/en/function.http-redirect.php
Related topics
contact form
Need a simple Contact form
For those who need a contact form
I am trying to build a contact form using php and flash
PHP contact script...
contact form with IP feature ?
AJAX and PHP contact form
Contact Form prob
How to build simple PHP upload form
Need a Contact form from HTML/PHP
Need help to make my Flash contact form functioning!
Easy Contact Form with Instructions
Spam protection for contact form?
Contact Form Issues
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.