...

View Full Version : Contact form works in PHP 5 but need for 4.3.10



robdog119
05-02-2006, 03:21 PM
Hi there,
I have a contact form script that someone nicely helped me out with, but I can't get it to work. The user I got it from said that it was tested and worked but that was in PHP 5. I have PHP 4.3.10 and I'm wondering if that is the problem. If someone wouldn't mind taking a look to see what might need to be adjusted, I would appreciate it. It's a pretty clean script, but let me know if there are any questions. Thanks!


<?php

ob_start("ob_gzhandler");

session_start();

//#################################################################################################### ################################################
//#################################################################################################### ################################################
//##
//## These are the the only definable elements in the script.
//## Other than the look and feel of your form, which is at the bottom of the page.
//##
//##
$contactowner = "1"; // "1" = email the site owner ($contactemail)
$contactemail = "address1@email.com"; // Site owners email address
$contactadmin = "address2@email.com"; // Your / Webamster email address
//##
//##
//##
//#################################################################################################### ################################################
//#################################################################################################### ################################################


if (isset($_POST['submit']))
{

$name = $_SESSION['name'] = $_POST['name'];
$address = $_SESSION['address'] = $_POST['address'];
$city = $_SESSION['city'] = $_POST['city'];
$state = $_SESSION['state'] = $_POST['state'];
$zip = $_SESSION['zip'] = $_POST['zip'];
$country = $_SESSION['country'] = $_POST['country'];
$phone = $_SESSION['phone'] = $_POST['phone'];
$email = $_SESSION['email'] = $_POST['email'];
$find = $_SESSION['find'] = addslashes($_POST['find']);
$question = $_SESSION['question'] = addslashes($_POST['question']);


if((isset($_SESSSION['complete'])) and ($_SESSION['complete'] == "True"))
{

header("Location: ". $_SERVER['PHP_SELF'] . "?msg=You have already Submitted this form.");

}
if(empty($_POST['name']) ||
empty($_POST['address']) ||
empty($_POST['city']) ||
empty($_POST['state']) ||
empty($_POST['zip']))
{

header("Location: ". $_SERVER['PHP_SELF'] . "?msg=You must enter all required fields");

}
else
{

if(mysql_query("INSERT INTO `guestbook` (name,
address,
city,
state,
zip,
country,
phone,
email,
find,
question)
VALUES ('$name',
'$address',
'$city',
'$state',
'$zip',
'$country',
'$phone',
'$email',
'$find',
'$question')"))

{

if($contactowner == "1")
{
$to = $contactemail;
$admin = $contactadmin;
$subject = 'Mailing List Submission to the Redmond Bennet Gallery';

$message = "Thank you for joining our mailing list."."\r\n".
"Name : ".$name."\r\n".
"Email : ".$email."\r\n";
$message .= wordwrap($question, 70);

$comment = "The following person has joined your mailing list."."\r\n".
"Name : ".$name."\r\n".
"Email : ".$email."\r\n";
$comment .= wordwrap($question, 70);

$headers = 'From: '. $to . "\r\n" .
'Reply-To: '. $to . "\r\n" .
'Cc:' . "\r\n".
'Bcc: '. $admin . "\r\n".
'X-Mailer: PHP/' . phpversion();



mail($to, $subject, $comment, $headers);
mail($email, $subject, $message, $headers);

}

$_SESSION['complete'] = "True";
header("Location: ". $_SERVER['PHP_SELF'] . "?msg=Thank you for submitting this form,&lt;br&gt; Your Details have been stored.");

}
else
{

header("Location: ". $_SERVER['PHP_SELF'] . "?msg=Im sorry there was an error in our database, Please try again.");

}

}


}

?>

MRMAN
05-02-2006, 03:24 PM
what is the problem you are getting?

robdog119
05-02-2006, 06:02 PM
Well, it seems to lock up the server. I've had to call my host twice to have them reboot. After you click submit, it just hangs and doesn't go anywhere, but the browser's activity indicator continues to spin. At one point I took some of the code out and it put the info into the db, but in attempting to try and repeat that, I locked it up again. I'll keep trying.

ralph l mayo
05-02-2006, 06:10 PM
Well, it seems to lock up the server. I've had to call my host twice to have them reboot.
lulz

I don't know what's wrong, but the PHP version is a red herring because all the stuff you've used has been around at since at least PHP 4.1.

edit: oh there's no case for $_GET['msg'] being set so it might be caught in a redirect loop if for some reason $_POST is persisting... it shouldn't be, but try it out.
edit 2: also maybe you need ob_flush() at the end.

robdog119
05-02-2006, 08:17 PM
Perhaps you are correct. I do use the following later on in the page:

<form id="MailingList" action="<?php echo($_SERVER['PHP_SELF']); ?>" method="POST" name="guestbook">
<?php
if(isset($_GET['msg']))
{
echo("<div style=\"color: #990000; font-size: 18px;\">" . $_GET['msg'] . "</div>");
}
?>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<tr>...etc.

Where would I set $_GET['msg'], and what do I set it to? Thanks!

robdog119
05-08-2006, 04:43 PM
Well, I've gotten closer on this. I found that if I move my db login information up to the top of the page just before ob_start, the script now takes the form information and enters it into the db as well as sends the e-mails to the correct addresses. However, I don't get either a confirmation message or error message (if all default fields are not entered), it submits the info but then just hangs on that page. Where is the best location for that login information anyway? Any thoughts are greatly appreciated! Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum