LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-11-2009, 03:20 PM   #1
jeweline
LQ Newbie
 
Registered: Sep 2009
Posts: 7

Rep: Reputation: Disabled
Problem with PHP form not submitting on IE 8, But does submit on Firefox and Chrome


Hi All,

I am a newbie to this site, as well as being a newbie with using scripting languages.

I've created a PHP contact form that when the submit button is clicked, I want it to send an e-mail to a certain address. Thanks so much for taking the time to look at this and help me! I'm so confused and frustrated!

I created the form in Dreamweaver. I first added code for server-side verification of the fields and then I used Dreamweaver's Spry Validation widgets to add client-side verification of the form elements.

In Firefox and Google Chrome, when I test the form by correctly filling out the different form elements and clicking the submit button:
  1. the form gets submitted
  2. the "thank you" message correctly displays
  3. and I receive an e-mail in my mailbox

The problem is with Internet Explorer 8. When I test the form by correctly completing the various form elements and clicking the submit button:

The form doesn't get submitted because
  1. I see the following statement "Sorry, there was a problem sending your message. Please try later." This statement displays because part of an "If-then-else" statement failed. It is part of the client-side verification code I created
  2. Since, the form wasn't submitted, I don't get the resulting e-mail.

I really don't know enough about PHP to debug. All I can figure is that for some reason IE thinks the $_POST and $mailSent variables are empty, so it displays the "sorry, there was a problem" error message.

Here's the code I'm using in the contact form page to display either error messages or a confirmation message:

<div id="formintro">

PHP Code:
if ($_POST && isset($missing) && !empty($missing)) { 
<p class="warning2"><strong>Please complete the missing item(s) indicated.</strong></p>
PHP Code:
} elseif ($_POST && !$mailSent) {
?>
  <p class="warning2">Sorry, there was a problem sending your message. Please try later.</p>
<?php
} elseif ($_POST && $mailSent) {
?>
  <p class="acknowledgement"><strong>Thanks so much for taking the time to send us a note! We’ve received your message, and will contact you shortly!</strong></p>
} ?>

<p>Simply provide your information in the spaces provided below along with your comments or questions. You may also e-mail, call or write us directly with the provided information. <span style="color:#a91609; font-weight:bold;">Fields marked with an asterisk (*) are required and must be completed.</span>
</p>
</div>

The code to send the e-mail is in a separate include file. Here's the code I'm using to send the e-mail:

$mailSent = mail($to, $subject, $message, $headers);
if ($mailSent) {
// $missing is no longer needed if the email is sent, so unset it
unset($missing);
}

Here's a link to the form: http://www.buypuresilverbullion.com/.../contactus.php


Here's the code of the include file that contains the script to process the form:

Code:
<?php
if (isset($_SERVER['SCRIPT_NAME']) && strpos($_SERVER['SCRIPT_NAME'], '.inc.php')) exit;

// remove escape characters from POST array
if (PHP_VERSION < 6 && get_magic_quotes_gpc()) {
  function stripslashes_deep($value) {
    $value = is_array($value) ? array_map('stripslashes_deep', $value) : stripslashes($value);
	return $value;
  }
  $_POST = array_map('stripslashes_deep', $_POST);
}

// assume that there is nothing suspect
  $suspect = false;
  // create a pattern to locate suspect phrases
  $pattern = '/Content-Type:|Bcc:|Cc:/i';
  
  // function to check for suspect phrases
  function isSuspect($val, $pattern, &$suspect) {
    // if the variable is an array, loop through each element
    // and pass it recursively back to the same function
    if (is_array($val)) {
      foreach ($val as $item) {
         isSuspect($item, $pattern, $suspect);
      }
    } else {
      // if one of the suspect phrases is found, set Boolean to true
      if (preg_match($pattern, $val)) {
        $suspect = true;
      }
    }
  }

  // check the $_POST array and any subarrays for suspect content
  isSuspect($_POST, $pattern, $suspect);

  if ($suspect) {
    $mailSent = false;
    unset($missing);
  } else {
    // process the $_POST variables
    foreach ($_POST as $key => $value) {
      // assign to temporary variable and strip whitespace if not an array
      $temp = is_array($value) ? $value : trim($value);
      // if empty and required, add to $missing array
      if (empty($temp) && in_array($key, $required)) {
        array_push($missing, $key);
      } elseif (in_array($key, $expected)) {
	    // otherwise, assign to a variable of the same name as $key
        ${$key} = $temp;
      }
    }
  }
  
  // validate the email address
  if (!empty($email)) {
    // regex to identify illegal characters in email address
    $checkEmail = '/^[^@]+@[^\s\r\n\'";,@%]+$/';
	// reject the email address if it doesn't match
    if (!preg_match($checkEmail, $email)) {
      $suspect = true;
      $mailSent = false;
      unset($missing);
    }
  }

  
  // go ahead only if not suspect and all required fields OK
  if (!$suspect && empty($missing)) {
  
     // initialize the $message variable
     $message = '';
     // loop through the $expected array
     foreach($expected as $item) {
       // assign the value of the current item to $val
       if (isset(${$item}) && !empty(${$item})) {
         $val = ${$item};
       } else {
         // if it has no value, assign 'Not selected'
         $val = 'Not selected';
       }
       // if an array, expand as comma-separated string
       if (is_array($val)) {
         $val = implode(', ', $val);
       }
       // add label and value to the message body
       $message .= ucfirst($item).": $val\n\n";
     }

    // limit line length to 70 characters
    $message = wordwrap($message, 70);

     // create Reply-To header
     if (!empty($email)) {
       $headers .= "\r\nReply-To: $email";
     }

	 
    // send it  
 
    $mailSent = mail($to, $subject, $message, $headers);
    if ($mailSent) {
      // $missing is no longer needed if the email is sent, so unset it
	  unset($missing);
    }
  }
?>
 
Old 09-11-2009, 10:35 PM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Since PHP runs on the server generally it doesn't matter which browser is being used. I'd suggest that you print out what details the server is receiving. You can dothis with a
PHP Code:
var_dump($_POST); 
statement at the start of your code.
 
Old 09-12-2009, 01:09 AM   #3
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
Quote:
contact form that when the submit button is clicked,
it has been a while ( and ie 6 and 7 ) but is that button made in the apache style sheet .css
if so then IE will not make the button right( MS uses a .css ass-backwards, and in there very odd way - ignoring the w3c ) and you might need a java script for that button to be made in IE 8
 
Old 09-12-2009, 07:53 PM   #4
jeweline
LQ Newbie
 
Registered: Sep 2009
Posts: 7

Original Poster
Rep: Reputation: Disabled
Thanks so much for your help. No the button is not created in apache css. It's hardcoded in HTML within the page.

Thanks!
 
Old 09-12-2009, 08:56 PM   #5
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Were you able to get the details of the $_POST variable?
Were they different between the various browsers?
 
Old 09-13-2009, 12:12 AM   #6
jeweline
LQ Newbie
 
Registered: Sep 2009
Posts: 7

Original Poster
Rep: Reputation: Disabled
Gramef,

Here's the code from using the "var_dump($_POST);" statement. Thank you so much!

Code:
array(17) { ["First_Name"]=>  string(7) "cynthia" ["Last_Name"]=>  string(5) "owens" ["company"]=>  string(0) "" ["Street_Address1"]=>  string(16) "ssssssssssssssss" ["Street_Address2"]=>  string(1) "s" ["city"]=>  string(16) "ssssssssssssssss" ["state_region"]=>  string(16) "ssssssssssssssss" ["Postal_Code"]=>  string(12) "ssssssssssss" ["country_code"]=>  string(2) "JM" ["url"]=>  string(0) "" ["daytime_phone"]=>  string(12) "111-111-1111" ["evening_phone"]=>  string(0) "" ["email2"]=>  string(0) "" ["comments"]=>  string(28) "testing webform on my server" ["prefer_to_be_contacted_by"]=>  string(5) "Email" ["best_time_to_call"]=>  string(7) "Morning" ["send"]=>  string(22) "Send Us Your Comments!" }
Warning: Cannot modify header information - headers already sent by (output started at /home1/buypures/public_html/silverlinemarket2/contactus.php:2) in /home1/buypures/public_html/silverlinemarket2/includes/process_mail.inc.php on line 103
 
Old 09-13-2009, 12:44 AM   #7
jeweline
LQ Newbie
 
Registered: Sep 2009
Posts: 7

Original Poster
Rep: Reputation: Disabled
graemef

I'm sorry, here's the correct code I got when trying to use the form after changing the script to display a confirmation in the same page as the form instead of redirecting it to a separate thank you page.:

Code:
array(17) 
{ 
["First_Name"]=> string(7) "cynthia" 
["Last_Name"]=> string(10) "owens-ali4" 
["company"]=> string(0) "" ["Street_Address1"]=> string(15) "125 main street" 
["Street_Address2"]=> string(0) "" 
["city"]=> string(8) "anywhere" 
["state_region"]=> string(5) "state" 
["Postal_Code"]=> string(6) "111111" 
["country_code"]=> string(2) "US" ["url"]=> string(0) ""
["daytime_phone"]=> string(12) "000-000-0000" 
["evening_phone"]=> string(0) "" 
["email2"]=> string(0) "" 
["comments"]=> string(73) "Matt, if you receive this e-mail, please disregard. I am still debugging." 
["prefer_to_be_contacted_by"]=> string(5) 
"Email" 
["best_time_to_call"]=> string(7) "Morning" 
["send"]=> string(22) "Send Us Your Comments!" } 
Warning: mail() [function.mail]: SMTP server response: 451 
See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\4750285\html\includes\process_mail.inc.php on line 100
 
Old 09-13-2009, 01:52 AM   #8
jeweline
LQ Newbie
 
Registered: Sep 2009
Posts: 7

Original Poster
Rep: Reputation: Disabled
graemef

I'm sorry, here's the correct code I got when trying to use the form after changing the script to display a confirmation in the same page as the form instead of redirecting it to a separate thank you page.:

Code:
array(17) 
{ 
["First_Name"]=> string(7) "cynthia" 
["Last_Name"]=> string(10) "owens-ali4" 
["company"]=> string(0) "" ["Street_Address1"]=> string(15) "125 main street" 
["Street_Address2"]=> string(0) "" 
["city"]=> string(8) "anywhere" 
["state_region"]=> string(5) "state" 
["Postal_Code"]=> string(6) "111111" 
["country_code"]=> string(2) "US" ["url"]=> string(0) ""
["daytime_phone"]=> string(12) "000-000-0000" 
["evening_phone"]=> string(0) "" 
["email2"]=> string(0) "" 
["comments"]=> string(73) "Matt, if you receive this e-mail, please disregard. I am still debugging." 
["prefer_to_be_contacted_by"]=> string(5) 
"Email" 
["best_time_to_call"]=> string(7) "Morning" 
["send"]=> string(22) "Send Us Your Comments!" } 
Warning: mail() [function.mail]: SMTP server response: 451 
See http://pobox.com/~djb/docs/smtplf.html. in D:\Hosting\4750285\html\includes\process_mail.inc.php on line 100
 
Old 09-13-2009, 01:58 AM   #9
jeweline
LQ Newbie
 
Registered: Sep 2009
Posts: 7

Original Poster
Rep: Reputation: Disabled
Hi Y'all,

Thanks so much for all your help. I found the problem.

It was in the include file. There was a problem with the $message statement that was to build the e-mail message.

This is what I had:

// add label and value to the message body
$message .= ucfirst($item).": $val\n\n";

It should be

// add label and value to the message body
$message .= "ucfirst($item): $val\n\n";
 
Old 09-13-2009, 02:10 AM   #10
jeweline
LQ Newbie
 
Registered: Sep 2009
Posts: 7

Original Poster
Rep: Reputation: Disabled
Smile

I mean it should be:

PHP Code:
// add label and value to the message body
$message .= "ucfirst($item): $val\r\n\r\n"
Thanks again!
 
Old 04-26-2010, 11:23 AM   #11
brandon74
LQ Newbie
 
Registered: Apr 2010
Posts: 4

Rep: Reputation: 0
You need to go to php form tutorials and find there the solution
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php form submit code not working FirstBorn Programming 3 12-27-2008 07:08 AM
PHP: submitting a form to one of two pages ALInux Programming 7 11-12-2005 05:40 PM
PHP form takes forever to submit newuser455 Programming 3 06-09-2005 04:17 AM
is this php automatic form submit post wriiten correctly? fsock error.. verbatim Programming 1 05-11-2005 10:24 AM
Submitting a POST Form with Links HappyDude Programming 0 10-24-2004 02:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:44 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration