Page 1 of 1

This form is driving me mad!

Posted: Tue Feb 02, 2010 5:11 am
by nikita68
Hi,
I have a form in php that is working fine in Firefox but not it IE...
It redirects the user to a page once the form is submitted; it does work in Firefox but not in IE.

The data of the form is sent to my email address. When I submitthe form in IE, it shows me the error message instead of redirecting me the right page. However, I do receive the email to my mailbox like it should be.

Here is the code. I hope someone can help me! :banghead:

PHP CODE

Code: Select all

<?php
$to = $_REQUEST['sendto'] ;
$from = $_REQUEST['Email'] ;
$name = $_REQUEST['Name'] ;
$hidden = $_REQUEST['Hidden'] ;
$headers = "From: $from";
$subject = "Web Contact Data";
 
$fields = array();
$fields{"Name"} = "Name";
$fields{"Company"} = "Company";
$fields{"Email"} = "Email";
$fields{"Phone"} = "Phone";
$fields{"list"} = "Mailing List";
$fields{"Message"} = "Message";
 
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
 
$headers2 = "From: myemail@box.net";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Here is the link to the brochures. If you encounter an error, please notify it to our website manager by sending an email to that address: email@box.net . '<br />' .  Link to brochure page: http://www.page.net/page.html   ";
 
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.mysite.net/index.php/page.html" );
exit;
}
else
{print "We encountered an error sending your mail, please notify webmaster@box.net"; }
}
}
?>
HTML CODE

Code: Select all

<form method="post" action="contact.php">
 
<table bgcolor=#ebf6c6 align=center ">
<tr><td> <input type="hidden" size=25 name="sendto" value="email@box.net"></td></tr>
<tr>
<b> Download our brochures <small> (full details of our services & products) </small> </b> 
<td><font color=red>*</font> Name:</td><td><input size=15 name="Name"></td>
<td><font color=red>*</font> Email:</td><td><input size=15 name="Email"></td>
<td colspan=2 align=center><input type=submit name="send" value="Submit"></td>
</tr>
</table>
<div align=center> <small> A link will be send to your mail box to download the brochures in a PDF format.</small> </div>
</form>
Thank for any help!

Re: This form is driving me mad!

Posted: Tue Feb 02, 2010 9:13 am
by nikita68
Nobody to help on this? :|

Re: This form is driving me mad!

Posted: Tue Feb 02, 2010 4:54 pm
by social_experiment
This probably isn't the best solution out there but i tested it and it worked, in both IE and FireFox. I added ob_flush() and ob_end_flush() which starts and stops output buffering respectively.

Code: Select all

<?php ob_flush();
    $to = $_REQUEST['sendto'] ; 
    $from = $_REQUEST['Email'] ;
    $name = $_REQUEST['Name'] ;
    $hidden = $_REQUEST['Hidden'] ;
    $headers = "From: $from";
    $subject = "Web Contact Data";
     
   $fields = array();
   $fields{"Name"} = "Name";
   $fields{"Company"} = "Company";
   $fields{"Email"} = "Email";
   $fields{"Phone"} = "Phone";
   $fields{"list"} = "Mailing List";
   $fields{"Message"} = "Message";
    
   $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
    
   $headers2 = "From: myemail@box.net";
   $subject2 = "Thank you for contacting us";
   $autoreply = "Thank you for contacting us. Here is the link to the brochures. If you encounter an error, please notify it to our website manager by sending an email to that address: email@box.net . '<br />' .  Link to brochure page: http://www.page.net/page.html   ";
    
   if($from == '') {print "You have not entered an email, please go back and try again";}
   else {
   if($name == '') {print "You have not entered a name, please go back and try again";}
   else {
   $send = mail($to, $subject, $body, $headers);
   $send2 = mail($from, $subject2, $autoreply, $headers2);
   if($send)
   { header( "Location: http://www.mysite.net/index.php/page.html" );
    
   exit;
   }
   else
   {print "We encountered an error sending your mail, please notify webmaster@box.net"; }
   }
   }
   ob_end_flush();
  ?>
The HTML code is also a bit dodgy, change :

Code: Select all

<table bgcolor=#ebf6c6 align=center ">
to :

Code: Select all

<table bgcolor="#ebf6c6" align="center">
Rather uses external stylesheets :)

Re: This form is driving me mad!

Posted: Wed Feb 03, 2010 5:22 am
by nikita68
Thank you, it is working now!!
I can go back to a normal life now... :mrgreen: