Old 11-08-2006, 02:06   #1 (permalink)
shaunfowler
Registered User
 
Join Date: Jul 2006
Posts: 8
PHP Form - header()

Hey,

I made this php mail form and for some reason I cannot get the header() funtion to work.. It's probably simple, but I can't get it to work at all (the code is below). After the form is submitted with all the correct information, i want it to redirect to another page, in this case its just google.ca for now. I can get it to echo a success message, but it wont redirect with the header() and i havent sent anything to the browser previously to that.

How can i get this to redirect!?


Thanks in advance.

PHP Code:
<?php

if (isset($_POST['submit'])) {
    
    
$error = array();
    
    
// check the name
    
if (empty($_POST['name'])) {
        
$e_n "<img src=\"\images\exclaim.gif\" />";
        
$error[] = 'n';
    } else {
        
$n = ($_POST['name']);
    }
    
    
// check email address
    
if (empty($_POST['email'])) {
        
$e_e "<img src=\"\images\exclaim.gif\" />";
        
$error[] = 'e';
    } else {
        if (!
preg_match("/.*@.*..*/"$_POST['email']) | preg_match("/(<|>)/"$_POST['email'])) {
            
$e_e "<img src=\"\images\exclaim.gif\" />";
            
$error[] = 'n';
        }
        
$e = ($_POST['email']);
    }
    
    
// check company name
    
if (empty($_POST['company'])) {
        
$e_c "<img src=\"\images\exclaim.gif\" />";
        
$error[] = 'c';
    } else {
        
$c = ($_POST['company']);
    }
    
    
// check message body
    
if (empty($_POST['message'])) {
        
$e_m "<img src=\"\images\exclaim.gif\" />";
        
$error[] = 'm';
    } else {
        
$m = ($_POST['message']);
    }
    
    
// if there are no errors
    
if (empty($error)) {
        
$h "This message was sent from $n with $c.";
        
mail("*****@shaw.ca""Website Contact Form"$h$m);
        
header('Location: http://google.com');
        exit();
    } else {
        echo 
'<strong><font color="#6D747D">You have left a required field blank or entered incorrent information</font></strong>';
    }
}
?>
    
    <form action="contact.php" method="post">
    <table width="500" border="0" cellspacing="0" cellpadding="7">
      <tr>
        <td width="150">Full Name </td>
        <td width="330"><input name="name" type="text" class="textbox" size="30" maxlength="30" />&nbsp;<? echo "$e_n"?></td>
      </tr>
      <tr>
        <td>Reply E-mail Address </td>
        <td><input name="email" type="text" class="textbox" size="30" maxlength="50" />&nbsp;<? echo "$e_e"?></td>
      </tr>
      <tr>
        <td>Company Name </td>
        <td><input name="company" type="text" class="textbox" size="30" maxlength="50" />&nbsp;<? echo "$e_c"?></td>
      </tr>
      <tr>
        <td height="144" valign="top">Your Message</td>
        <td><textarea name="message" cols="35" rows="10" class="textbox"></textarea>&nbsp;<? echo "$e_m"?></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input type="submit" value="Submit" name="submit" /></td>
      </tr>
    </table>
    </form>
  Reply With Quote
Old 11-08-2006, 03:29   #2 (permalink)
d*d
Senior Member
 
d*d's Avatar
 
Join Date: Oct 2004
Location: Bristol
Posts: 3,155
headers have to be send out at the top of the page before the html, you can't use half way through a page
  Reply With Quote
Old 11-08-2006, 03:37   #3 (permalink)
shaunfowler
Registered User
 
Join Date: Jul 2006
Posts: 8
I understand what you mean, but it shouldn't matter since it's in a conditional, or should it ? I've seen the header fuction used in the middle of pages in many website tutorials and books. Anywho, how would I reposition this?

Thanks again.

EDIT: Okay, i jammed that whole chunck of php code above every piece of html (even the <html> tag) and when i go to that page i just get the blank white page in a browser....

any advice?

thanks

Last edited by shaunfowler : 11-08-2006 at 23:37.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8