Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-02-2006, 03:21 PM   PM User | #1
robdog119
New Coder

 
Join Date: Jan 2006
Location: New England
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
robdog119 is an unknown quantity at this point
Contact form works in PHP 5 but need for 4.3.10

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 Code:
<?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($question70);
            
            
$comment  "The following person has joined your mailing list."."\r\n".
                        
"Name  :  ".$name."\r\n".
                        
"Email :  ".$email."\r\n";
                         
$comment .= wordwrap($question70);
            
                         
$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.");
            
         }
            
      }
      
      
}

?>
robdog119 is offline   Reply With Quote
Old 05-02-2006, 03:24 PM   PM User | #2
MRMAN
Regular Coder

 
Join Date: Jan 2006
Location: Preston, Lancashire, England
Posts: 285
Thanks: 0
Thanked 0 Times in 0 Posts
MRMAN is an unknown quantity at this point
what is the problem you are getting?
MRMAN is offline   Reply With Quote
Old 05-02-2006, 06:02 PM   PM User | #3
robdog119
New Coder

 
Join Date: Jan 2006
Location: New England
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
robdog119 is an unknown quantity at this point
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.
robdog119 is offline   Reply With Quote
Old 05-02-2006, 06:10 PM   PM User | #4
ralph l mayo
Regular Coder

 
ralph l mayo's Avatar
 
Join Date: Nov 2005
Posts: 951
Thanks: 1
Thanked 31 Times in 29 Posts
ralph l mayo is on a distinguished road
Quote:
Originally Posted by robdog119
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.

Last edited by ralph l mayo; 05-02-2006 at 06:20 PM..
ralph l mayo is offline   Reply With Quote
Old 05-02-2006, 08:17 PM   PM User | #5
robdog119
New Coder

 
Join Date: Jan 2006
Location: New England
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
robdog119 is an unknown quantity at this point
Perhaps you are correct. I do use the following later on in the page:
PHP Code:
<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 is offline   Reply With Quote
Old 05-08-2006, 04:43 PM   PM User | #6
robdog119
New Coder

 
Join Date: Jan 2006
Location: New England
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
robdog119 is an unknown quantity at this point
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!
robdog119 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:09 AM.


Advertisement
Log in to turn off these ads.