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" /> <? echo "$e_n"; ?></td>
</tr>
<tr>
<td>Reply E-mail Address </td>
<td><input name="email" type="text" class="textbox" size="30" maxlength="50" /> <? echo "$e_e"; ?></td>
</tr>
<tr>
<td>Company Name </td>
<td><input name="company" type="text" class="textbox" size="30" maxlength="50" /> <? 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> <? echo "$e_m"; ?></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Submit" name="submit" /></td>
</tr>
</table>
</form>