LinuxQuestions.org
Visit Jeremy's Blog.
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-21-2009, 09:00 AM   #1
jamesmage
LQ Newbie
 
Registered: Sep 2009
Posts: 2

Rep: Reputation: 0
Contact form using PHP is not working in IE but works in FF.


Firstly hello everyone!

I was wondering if someone could help me with my php script handling form data sent from an HTML form. I am very new to using PHP and only have experience using HTML and CSS to build websites.

I have recently built a small website for a local company who wanted a custom contact form, so I used a free online php form generator and modified the script to accommodate / validate the new form fields. It has been uploaded today and works fine in FF and Safari, allowing the form data to be sent to the client as an email.

The problem is that Internet Explorer (have tested 6 and 8) doesn't like it. It just takes you to a the 'Internet Explorer cannot display this webpage' screen, with the php script location showing in the address bar. It does not show either the success.htm or error.htm pages that the script is set to point to.

I know I've probably messed up the script by modifying it, but I can't see what I've done wrong. The php form is in the same directory as the contact form, respectively named 'contact.htm' and 'feedback.htm'.

If someone who knows more about php could explain a simple fix to the problem I'd be most grateful! I didn't want the php form to be anything incredible, just to validate there was information in the required fields and pass that information through via email.

Here is the php script, followed by the html form. I haven't included the .css for the page, but i've tried removing the classes and it isn't causing the problem.

feedback.php:
Code:
<?php

/*
    CHFEEDBACK.PHP Feedback Form PHP Script Ver 2.15.0
    Generated by thesitewizard.com's Feedback Form Wizard 2.15.0.
    Copyright 2000-2009 by Christopher Heng. All rights reserved.
    thesitewizard is a trademark of Christopher Heng.

    Get the latest version, free, from:
        http://www.thesitewizard.com/wizards/feedbackform.shtml
	
*/

// ------------- CONFIGURABLE SECTION ------------------------

// $mailto - set to the email address you want the form
// sent to, eg
//$mailto		= "youremailaddress@example.com" ;

$mailto = 'info@everycloudmanagement.co.uk' ;

// $subject - set to the Subject line of the email, eg
//$subject	= "Feedback Form" ;

$subject = "Website Contact Form" ;

// the pages to be displayed, eg
//$formurl		= "http://www.example.com/feedback.html" ;
//$errorurl		= "http://www.example.com/error.html" ;
//$thankyouurl	= "http://www.example.com/thankyou.html" ;

$formurl = "http://www.everycloudmanagement.co.uk/contact.htm" ;
$errorurl = "http:///www.everycloudmanagement.co.uk/error.htm" ;
$thankyouurl = "http:///www.everycloudmanagement.co.uk/success.htm" ;

$email_is_required = 1;
$name_is_required = 1;
$enquiry_is_required = 1;
$phone_is_required = 1;
$method_is_required = 1;
$uself = 0;
$use_envsender = 0;
$use_sendmailfrom = 0;
$use_webmaster_email_for_from = 0;
$use_utf8 = 1;
$my_recaptcha_private_key = '' ;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ;
$content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-Type: text/plain; charset="utf-8"' ;
if (!isset( $use_envsender )) { $use_envsender = 0 ; }
if (isset( $use_sendmailfrom ) && $use_sendmailfrom) {
	ini_set( 'sendmail_from', $mailto );
}
$envsender = "-f$mailto" ;
$company = $_POST['company'] ;
$address = $_POST['address'] ;
$fullname = (isset($_POST['fullname']))? $_POST['fullname'] : $_POST['name'] ;
$email = $_POST['email'] ;
$phone = $_POST['phone'] ;   
$enquiry = $_POST['enquiry'] ;
$method = $_POST['method'] ;
$http_referrer = getenv( "HTTP_REFERER" );

if (!isset($_POST['email'])) {
	header( "Location: $formurl" );
	exit ;
}
if (($email_is_required && (empty($email) || !preg_match('/@/', $email))) || ($name_is_required && empty($fullname)) || ($enquiry_is_required && empty($enquiry)) || ($phone_is_required && empty($phone)) || ($method_is_required && empty($method))) {
	header( "Location: $errorurl" );
	exit ;
}
if ( preg_match( "/[\r\n]/", $fullname ) || preg_match( "/[\r\n]/", $email ) ) {
	header( "Location: $errorurl" );
	exit ;
}
if (strlen( $my_recaptcha_private_key )) {
	require_once( 'recaptchalib.php' );
	$resp = recaptcha_check_answer ( $my_recaptcha_private_key, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] );
	if (!$resp->is_valid) {
		header( "Location: $errorurl" );
		exit ;
	}
}
if (empty($email)) {
	$email = $mailto ;
}
$fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email : $mailto ;

if (function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc()) {
	$enquiry = stripslashes( $enquiry );
}

$messageproper =
	"This message was sent from:\n" .
	"$http_referrer\n" .
	"------------------------------------------------------------\n" .
	"Name: $fullname\n" .
	"Email: $email\n" .
	"Company Name: $company\n" . 
	"Address:\n" .
	$address .
	"\nTel: $phone\n" .
	"\nPreferred method of contact: $method\n" .
	"\nNature of enquiry:\n" .
	$enquiry .
	"\n\n------------------------END-----------------------------------\n" ;

$headers =
	"From: \"$fullname\" <$fromemail>" . $headersep . "Reply-To: \"$fullname\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.15.0" .
	$headersep . 'MIME-Version: 1.0' . $headersep . $content_type ;

if ($use_envsender) {
	mail($mailto, $subject, $messageproper, $headers, $envsender );
}
else {
	mail($mailto, $subject, $messageproper, $headers );
}
header( "Location: $thankyouurl" );
exit ;

?>
And the HTML form:

Code:
<form id="contactform" action="feedback.php" method="post">
<fieldset>
<legend>Contact Form</legend>

<p>(Fields marked * are required)</p>

<p><label for="tswcompany">Company Name:</label><input type="text" name="company" id="tswcompany" size="25"/></p>

<p><label for="tswaddress">Address:</label><textarea rows="5" cols="25" name="address" id="tswaddress"></textarea></p>

<p><label for="tswemail">Email:</label><input type="text" id="tswemail" name="email" size="25" value="*" /></p>

<p><label for="tswephone">Tel Nr:</label><input type="text" name="phone" size="13" id="tswphone" value="*" /></p>

<p><label for="tswname">Name:</label><input type="text" name="fullname" id="tswname" size="25" value="*" /></p>

<p><label for="tswenquiry">Nature of enquiry:</label><textarea rows="8" cols="55" name="enquiry" id="tswenquiry">*</textarea></p>

<p><label for="tswcontactmethod">Preferred method of contact:</label>
<select name="method" id="tswmethod" />
<option value="">Please select *</option>
<option value="email">Email</option>
<option value="phone">Phone</option>
<option value="post">Post</option>
</select>
</p>

<p class="submit"><input type="submit" value="submit" /></p>
</fieldset>
</form>
Any help would be really appreciated!

Thanks,

James
 
Old 09-21-2009, 10:10 AM   #2
TB0ne
Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 14,642

Rep: Reputation: 2574Reputation: 2574Reputation: 2574Reputation: 2574Reputation: 2574Reputation: 2574Reputation: 2574Reputation: 2574Reputation: 2574Reputation: 2574Reputation: 2574
Quote:
Originally Posted by jamesmage View Post
Firstly hello everyone!

I was wondering if someone could help me with my php script handling form data sent from an HTML form. I am very new to using PHP and only have experience using HTML and CSS to build websites.

I have recently built a small website for a local company who wanted a custom contact form, so I used a free online php form generator and modified the script to accommodate / validate the new form fields. It has been uploaded today and works fine in FF and Safari, allowing the form data to be sent to the client as an email.

The problem is that Internet Explorer (have tested 6 and 8) doesn't like it. It just takes you to a the 'Internet Explorer cannot display this webpage' screen, with the php script location showing in the address bar. It does not show either the success.htm or error.htm pages that the script is set to point to.

I know I've probably messed up the script by modifying it, but I can't see what I've done wrong. The php form is in the same directory as the contact form, respectively named 'contact.htm' and 'feedback.htm'.

If someone who knows more about php could explain a simple fix to the problem I'd be most grateful! I didn't want the php form to be anything incredible, just to validate there was information in the required fields and pass that information through via email.

Here is the php script, followed by the html form. I haven't included the .css for the page, but i've tried removing the classes and it isn't causing the problem.

Any help would be really appreciated!

Thanks,

James
This thread here:

http://www.linuxquestions.org/questi...chrome-754482/

dealt with a similar problem, and may help you out. IE isn't a very good browser, and if you spend any time coding pages, you're likely to run into this again. Everything else will work fine...except IE. And it's so widely known, there are even ways to code your pages, so they'll work in IE, too.

This page http://thescriptcenter.com/php-form-to-email.html has a bit more advanced form you might be able to make use of. http://www.hotscripts.com is another good site to check, too.

And I realize you're just learning PHP, but I'd strongly suggest NOT using form-generators. They're like FrontPage used to be...you got something that would work, but it's rarely as good as what you'd get if you hand-coded it. Most of the PHP forms I do, wind up as two-part forms...one page for the 'fill-in-the-blanks' part, where I do my data validation, checking, etc., and another form that processes that data, and performs the action.

Hope this helps. If not, shoot me an email, and I can send you a simple working form set for you to play with.
 
Old 09-21-2009, 10:15 AM   #3
gregorian
Member
 
Registered: Apr 2006
Location: India
Posts: 473

Rep: Reputation: 33
I'm surprised that it says that the page cannot be found. PHP is a server side scripting language which generates HTML for the browser. I can understand if the page doesn't display properly in IE, but the fact that it works in FF shows that the PHP script is able to atleast generate HTML.

This may sound silly, but can you access some other website? (say Google) My guess is some settings of IE are incorrect.
 
Old 09-21-2009, 10:24 AM   #4
jamesmage
LQ Newbie
 
Registered: Sep 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Hey Gregorian,

Thanks for the response. I was able to surf around other websites no problem so it didn't appear to be incorrect settings, worth checking tho.

The problem has been solved it turns out the php script was sending the data through, it was just IE wasn't displaying the success or error page. Turns out i had 'http:///www.etc etc', too many slashes! In my haste in modifying the code, i must have not deleted a slash and failed to see it. Doh!

Its all working fine now thankfully!

Thanks for taking a look at it for me.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Looking for PHP Contact Importer that works with yahoo, hotmail, gmail , more michaeljoser Programming 1 12-27-2007 11:48 AM
Need a contact form vafe Linux - Software 2 05-23-2007 07:58 AM
Simple php script with html form not working. sinsoush Programming 4 04-01-2004 08:02 PM
Simple PHP form not working... Booster Programming 4 02-23-2004 02:50 PM


All times are GMT -5. The time now is 05:25 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration