php 4.3.10 works! php 5.2.4 doesnt work :(

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
didster
Forum Newbie
Posts: 13
Joined: Fri Oct 31, 2008 11:32 am

php 4.3.10 works! php 5.2.4 doesnt work :(

Post by didster »

Hello, I am a newbie to php and the devnetwork forum, I have managed to slowly set up a web form. I coded it succesfully on a server with php 4.3.10 but I just get a blank screen using php 5.2.4. I imagine that it is probably going to be something small as it works and has something to do with the version but I have no idea where to look first! Please help, cheers

Code: Select all

<?
 
// ------------- CONFIGURABLE SECTION ------------------------
 
// $mailto - set to the email address you want the form
// sent to, eg
//$to       = "youremailaddress@example.com" ;
 
$to = '' ; //My email
// $subject - set to the Subject line of the email, eg
//$subject  = "Feedback Form" ;
 
$subject = "Plug Gauge Quote Request Form" ;
 
// the pages to be displayed, eg
//$formurl      = "http://www.example.com/contact.html" ;
//$errorurl     = "http://www.example.com/error.html" ;
//$thankyouurl  = "http://www.example.com/thankyou.html" ;
 
//$formurl = "http://www.paulfenlon.com/contactus.html" ;
//$errorurl = "http://www.paulfenlon.com/error.html" ;
//$thankyouurl = "http://www.paulfenlon.com/thankyou.html" ;
 
$formurl = "/pluggauge.htm";
$errorurl = "/spline/error.htm" ;
$thankyouurl = "/spline/thankyou.htm" ;
 
 
 
 
 
 
// -------------------- END OF CONFIGURABLE SECTION ---------------
 
 
$contactname = $_POST['contactname'] ;
$companyname = $_POST['companyname'] ;
$currentaddress = $_POST['currentaddress'] ;
$contactnumber = $_POST['contactnumber'] ;
$rfqreference = $_POST['rfqreference'] ;
$teeth = $_POST['teeth'] ;
$dpmoduletext = $_POST['dpmoduletext'] ;
$dpmoduledrop = $_POST['dpmoduledrop'] ;
$pressureangle = $_POST['pressureangle'] ;
$helixangle = $_POST['helixangle'] ;
$helixhand = $_POST['helixhand'] ;
$pitchtext = $_POST['pitchtext'] ;
$pitchdrop = $_POST['pitchdrop'] ;
$gauge = $_POST['gauge'] ;
$typefit = $_POST['typefit'] ;
$facetext = $_POST['facetext'] ;
$facedrop = $_POST['facedrop'] ;
$quantity = $_POST['quantity'] ;
$materials = $_POST['materials'] ;
$notes = $_POST['notes'] ;
 
 
$chknotest = $_POST['chkno'] ;
 
 
// Read POST request params into global vars
 
$from    = $_POST['from'];
 
// Obtain file upload vars
$fileatt      = $_FILES['fileatt']['tmp_name'];
$fileatt_type = $_FILES['fileatt']['type'];
$fileatt_name = $_FILES['fileatt']['name'];
 
$headers = "From: $from";
 
 
 
$file = fopen($filesize, 'rb');
if (filesize($fileatt)==0){}
else{$page_content = fread($file, filesize($fileatt));}
 
 
 
 
//                        ORIGINAL!
 
//  Read the file to be attached ('rb' = read binary)
 
//  $file = fopen($fileatt,'rb');
//  $data = fread($file,filesize($fileatt));
// fclose($file); 
 
 
 
//                        FIX FROM WEBSITE
 
//  if ($page_type == "f") {
//  $filename = "../pages/".$page_url.".php";
//  $handle = fopen($filesize, "r");
//  if (filesize($fileatt)==0){}
//  else{$page_content = fread($handle, filesize($fileatt));}
//  fclose($handle); 
 
//                      v1
 
//$file = fopen($filesize, "r");
//if (filesize($fileatt)==0){}
//else{$page_content = fread($file, filesize($fileatt));}
//fclose($file);
 
 
 
 
 
 
  // Generate a boundary string
  $semi_rand = md5(time());
  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
 
 
//line 62: if ($page_type == "f") {
//line 63: $filename = "../pages/".$page_url.".php";
//line 64: $handle = fopen($filesize, "r");
//if (filesize($fileatt))==0{}
//else{$page_content = fread($handle, filesize($fileatt));}
//line 66: fclose($handle); 
 
 
 
$message .=
 
"\n\n-- Chk --\n\n" .
 
$_POST['chkno'][0] .
$_POST['chkno'][1] .
$_POST['chkno'][2] ;
 
if (!empty($contactname)) {
    $message .= "\n\n-- Contact Name --\n\n" . $contactname;
}
 
if (!empty($companyname)) {
    $message .= "\n\n-- Company Name --\n\n" . $companyname;
}
 
if (!empty($currentaddress)) {
    $message .= "\n\n-- Current Address --\n\n" . $currentaddress;
}
 
if (!empty($contactnumber)) {
    $message .= "\n\n-- Contact Number --\n\n" . $contactnumber;
}   
 
if (!empty($rfqreference)) {
    $message .= "\n\n-- RFQ Reference Number --\n\n" . $rfqreference;
}
 
if (!empty($teeth)) {
    $message .= "\n\n-- Teeth --\n\n" . $teeth;
}
 
if (!empty($dpmoduletext)) {
    $message .= "\n\n-- DP Module Text --\n\n" . $dpmoduletext;
}
 
if (!empty($dpmoduledrop)) {
    $message .= "\n\n-- DP Module Drop --\n\n" . $dpmoduledrop;
}
 
if (!empty($pressureangle)) {
    $message .= "\n\n-- Pressure Angle --\n\n" . $pressureangle;    
}
 
if (!empty($helixangle)) {
    $message .= "\n\n-- Helix Angle --\n\n" . $helixangle;
}   
 
if (!empty($helixhand)) {
    $message .= "\n\n-- Helix Hand --\n\n" . $helixhand;
}
 
if (!empty($pitchtext)) {
    $message .= "\n\n-- Pitch Text (Check If Serration) --\n\n" . $dpmoduledrop . " " . $pitchtext;
}       
 
if (!empty($pitchdrop)) {
    $message .= "\n\n-- Pitch Drop (Check If Serration) --\n\n" . $dpmoduledrop . " " . $pitchdrop;
}
 
if (!empty($gauge)) {
    $message .= "\n\n-- Gauge Ref/Tool No. --\n\n" . $gauge;
}
 
if (!empty($typefit)) {
    $message .= "\n\n-- Type Fit --\n\n" . $typefit;
}
 
if (!empty($facetext)) {
    $message .= "\n\n-- Face Width Text --\n\n" . $facetext;
}
 
if (!empty($facedrop)) {
    $message .= "\n\n-- Face Width Drop --\n\n" . $facedrop;
}
 
if (!empty($quantity)) {
    $message .= "\n\n-- Quantity --\n\n" . $quantity;   
}
 
if (!empty($materials)) {
    $message .= "\n\n-- Materials --\n\n" . $materials;
}
 
if (!empty($notes)) {
    $message .= "\n\n-- Notes --\n\n" . $notes;
}
 
 
/* 
    $message .=
    
    "\n\n-- Chk --\n\n" .
 
$_POST['chkno'][0] .
$_POST['chkno'][1] .
$_POST['chkno'][2];
 
    "\n\n-- Contact Name --\n\n" .
    $contactname .  
    "\n\n-- Email Address --\n\n" .
    $from . 
    "\n\n-- Company Name --\n\n" .
    $companyname .  
    "\n\n-- Current Address --\n\n" .
    $currentaddress .
    "\n\n-- Contact Number --\n\n" .
    $contactnumber .
    "\n\n-- RFQ Reference Number --\n\n" .
    $rfqreference .
    "\n\n-- Teeth --\n\n" .
    $teeth .
    "\n\n-- DP Module Text --\n\n" .
    $dpmoduletext .
    "\n\n-- DP Module Drop --\n\n" .
    $dpmoduledrop .
    "\n\n-- Pressure Angle --\n\n" .
    $pressureangle .
    "\n\n-- Helix Angle --\n\n" .
    $helixangle .
    "\n\n-- Helix Hand --\n\n" .
    $helixhand .
    "\n\n-- Pitch Text (Check If Serration) --\n\n" .
    $dpmoduledrop . " " . $pitchtext .
    "\n\n-- Pitch Drop (Check If Serration) --\n\n" .
    $dpmoduledrop . " " . $pitchdrop .
    "\n\n-- Gauge Ref/Tool No. --\n\n" .
    $gauge .    
    "\n\n-- Type Fit --\n\n" .
    $typefit .
    "\n\n-- Face Width Text --\n\n" .
    $facetext .
    "\n\n-- Face Width Drop --\n\n" .
    $facedrop .
    "\n\n-- Quantity --\n\n" .
    $quantity . 
    "\n\n-- Materials --\n\n" .
    $materials .
    "\n\n-- Notes --\n\n" .
    $notes .
    "\n\n-----------\n\n " ;
 
*/
  
  
  // Add the headers for a file attachment
  $headers .= "\nMIME-Version: 1.0\n" .
              "Content-Type: multipart/mixed;\n" .
              " boundary=\"{$mime_boundary}\"";
 
  // Add a multipart boundary above the plain message
  $message = "This is a multi-part message in MIME format.\n\n" .
             "--{$mime_boundary}\n" .
             "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
             "Content-Transfer-Encoding: 7bit\n\n" .
             $message . "\n\n";
 
  // Base64 encode the file data
  $data = chunk_split(base64_encode($data));
 
  // Add file attachment to the message
  $message .= "--{$mime_boundary}\n" .
              "Content-Type: {$fileatt_type};\n" .
              " name=\"{$fileatt_name}\"\n" .
              //"Content-Disposition: attachment;\n" .
              //" filename=\"{$fileatt_name}\"\n" .
              "Content-Transfer-Encoding: base64\n\n" .
              $data . "\n\n" .
              "--{$mime_boundary}--\n";
 
 
 
 
 
$http_referrer = getenv( "HTTP_REFERER" );
 
if (!isset($_POST['from'])) {
    header( "Location: $formurl" );
    exit ;
}
 
if (empty($contactname) || empty($from) || empty($companyname) || empty($contactnumber) || empty($teeth) || empty($quantity) || empty($chknotest)/* || empty($dpmoduletext)  || empty($dpmoduledrop) || empty($currentaddress) || empty($rfqreference) || empty($pressureangle) ||  empty($helixangle) || empty($helixhand) || empty($pitchtext) || empty($pitchdrop) || empty($gauge) || empty($typefit) || empty($facetext) || empty($facedrop) || empty($quantity) || empty($materials) ||empty($notes) */) {
   header( "Location: $errorurl" );
   exit ;
}
 
 
$contactname = strtok( $contactname, "\r\n" );
$email = strtok( $email, "\r\n" );
if (get_magic_quotes_gpc()) {
 
    $chkno = stripslashes( $chkno );
 
    $companyname = stripslashes( $companyname );    
    $currentaddress = stripslashes( $currentaddress );
    $contactnumber = stripslashes( $contactnumber );
    $rfqreference = stripslashes( $rfqreference );
    $teeth = stripslashes( $teeth );    
    $dpmoduletext = stripslashes( $dpmoduletext );  
    $dpmoduledrop = stripslashes( $dpmoduledrop );
    $pressureangle = stripslashes( $pressureangle );
    $helixangle = stripslashes( $helixangle );
    $helixhand = stripslashes( $helixhand );
    $pitchtext = stripslashes( $pitchtext );
    $pitchdrop = stripslashes( $pitchdrop );
    $gauge = stripslashes( $gauge );    
    $typefit = stripslashes( $typefit );
    $facetext = stripslashes( $facetext );
    $facedrop = stripslashes( $facedrop );
    $quantity = stripslashes( $quantity );  
    $materials = stripslashes( $materials );
    $notes = stripslashes( $notes );
}
 
 
 
ini_set("sendmail_from", $email);
 
@mail($to, $subject, $message, $headers);
header( "Location: $thankyouurl" );
exit ;
 
?>
jackliu97
Forum Newbie
Posts: 4
Joined: Mon Dec 10, 2007 4:09 pm

Re: php 4.3.10 works! php 5.2.4 doesnt work :(

Post by jackliu97 »

why don't u put a check for the logic around lines 302, 307
if you get a blank that means something happened before it can get through to the header calls.

also make sure your error messages and warnings are turned on.

and try echoing some stuff... like.

Code: Select all

 
if(mail($to, $subject, $message, $headers))
header( "Location: $thankyouurl" );
else
echo 'fail at mail()';
 
didster
Forum Newbie
Posts: 13
Joined: Fri Oct 31, 2008 11:32 am

Re: php 4.3.10 works! php 5.2.4 doesnt work :(

Post by didster »

Cheers jackliu97,

That is bloody brilliant! I wanted to know the best way to test, as I say, I am a newbie so I will give it a go. Thanks so much
didster
Forum Newbie
Posts: 13
Joined: Fri Oct 31, 2008 11:32 am

Re: php 4.3.10 works! php 5.2.4 doesnt work :(

Post by didster »

Hello,

I have managed to get the php working to a point. I get no errors now but the email fails to send! Again it did on 4.3.10 but not the more recent version.

Thanks again
User avatar
Jaxolotl
Forum Contributor
Posts: 137
Joined: Mon Nov 13, 2006 4:19 am
Location: Argentina and Italy

Re: php 4.3.10 works! php 5.2.4 doesnt work :(

Post by Jaxolotl »

line 1
1 - did you check if short_open_tag turned on on your php configuration? because you are writing your code that way
2 - Do you have error_reporting = E_ALL ?
the point 2 will help you sending the error report to the output (usin it only while testing your scripts)
didster
Forum Newbie
Posts: 13
Joined: Fri Oct 31, 2008 11:32 am

Re: php 4.3.10 works! php 5.2.4 doesnt work :(

Post by didster »

I now have this set up. I added the <?php because "short_open_tag" is turned off on the new server. I wasnt aware of this so thankyou. I have added the error reporting lines as below but I get nothing, just the message that I coded to tell me that the email was successful or unsuccessful. Any ideas?

Code: Select all

<?php
 
 error_reporting(E_ALL);
 ini_set("display_errors", 1);
didster
Forum Newbie
Posts: 13
Joined: Fri Oct 31, 2008 11:32 am

Re: php 4.3.10 works! php 5.2.4 doesnt work :(

Post by didster »

I imagine this may have something to do with it? It is from the phpinfo file that I ran on the new server. Should the path have some content?

sendmail_from no value no value
sendmail_path no value no value
Post Reply