PHP5 incompatibility? Formerly good page goes bad

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
Cyberen
Forum Newbie
Posts: 13
Joined: Wed Jan 19, 2011 4:32 pm

PHP5 incompatibility? Formerly good page goes bad

Post by Cyberen »

So I've been tasked to work with this code which used to not only echo the products ordered but also sent it via e-mail, and I can't figure out what the problem is! It worked fine before but now it's not working, which makes me suspect that it's PHP5 incompatible. It worked fine on a PHP4 server.

WHAT USED TO WORK:

Echoing of what the customer ordered and also sent an e-mail containing what the customer ordered.

WHAT WORKS NOW:
The page shows up, the order is sent, and the customer gets an e-mail from our Credit Card Gateway as well as our website stating their transaction #s, addresses and name. All the stuff covered by the previous order page.

WHAT DOESN'T WORK NOW:
What exactly they ordered (the $items array) is not being sent to the e-mail nor echoed on the page. The array is being sent to this page hence print_r($_SESSION['cart']); working, but its not being shown to the customer nor e-mailed to them.

POSSIBLE CAUSES:
Moving to a PHP5 server, unknown formatting problem.

Here's the code in its entirety, I don't even get how $email.= works for so many different things. Any help as to possible problems or incompatibilities would be greatly appreciated.

Code: Select all

<?
ini_set('display_errors','On'); 
include 'db.php';
set_time_limit (400);
session_start();
header("Cache-control: private");

//quick fix to copy post vars
$_POST=$_SESSION['post_vars'];

print_r($_SESSION['cart']);
$itemnumms = sizeof($_SESSION['cart']);
$unique_orderid=date("dmsHyi");

$email="Thank you for ordering from Jezebelgallery.com\n\n";
$email.="Your order ID is: " . $unique_orderid . "\n\n";

$email.="Your order will take approximately 3-6 weeks to arrive. If you have any questions please call 1-866-JEZEBEL.\n\n";

$email.="Here is a list of your products:\n\n";
$num_items=0;
for($i=0;$i<$itemnumms;$i++){

 if($_VARS['action']=='rem' && $_VARS['id']==$i){
  $_SESSION['cart'][$i]="";
 }
 $val=$_SESSION['cart'][$i];
 $items= split("\|\|",$val);
 if($items[0]!=""){ 
   $query = "SELECT *,category from products,categories where categories.id=products.pid and products.id=" . $items[0];
  $result = mysql_query($query) or die("Query failed : " . mysql_error());
  $line = mysql_fetch_array($result, MYSQL_ASSOC);


$email.= stripslashes($line['category']) . ":" .  stripslashes($line['name']) . "\n";
if($line['dims']!=''){
$email.="Dimensions: " . stripslashes($line['dims']) . "\n";
}
if($items[1]!=''){ 
$email.="Glass Color: " .  stripslashes($items[1]) . "\n";
}
if($items[2]!=''){
$email.="Finish: " . stripslashes($items[2]) . "\n";
}
if($items[3]!=''){
$email.="Stocks: " .  stripslashes($items[3]) . "\n";
}
if($items[4]!=''){
$email.="Cord Color: " . stripslashes($items[4]) . "\n";
}
if($items[5]!=''){ 
 $ceiling= split("\|",stripslashes($items[5]));
 $email.="Ceiling Height: " . $ceiling[0] . "\n";
}
if($items[6]!=''){
$email.="Glass Shape: " .  stripslashes($items[6]) . "\n";
}
if($items[7]!=''){
$email.="Leaf Option: " . stripslashes($items[7]) . "\n";
}
if($items[8]!=''){
 $email.="Ceiling Cap: " . stripslashes($items[8]) . "\n";
}
  mysql_free_result($result);
  if($line['ceiling']=='Y' && $line['static']=='N'){
    $ceiling= split("\|",stripslashes($items[5]));

	$query = "SELECT * from ceiling where deleted=0 and pid=" . $items[0];
	$result2 = mysql_query($query) or die("Query failed : " . mysql_error());
	$ceil_cost = mysql_fetch_array($result2, MYSQL_ASSOC);
	$line['price']=$ceil_cost['h' . $ceiling[0]];
	mysql_free_result($result2); 
  }
  $email.="Price: $" . $line['price'] . "\n\n";
  $total+=$line['price'];
  $num_items++;
 }
}

$email.="Total # of products:" . $num_items . "\n";

//adjust the price based on discount
if($_SESSION['discount']>0){ 
  $email.="Discount:" . $_SESSION['discount'] . "%\n";
  $total=$total*((100-$_SESSION['discount'])/100);
  unset($_SESSION['discount']);
} 

//Calculate shipping as 10% of total or $15 whichever is higher
//$shipping=0.1*$total;
//if($shipping<15.00){
//  $shipping=15.00;
$idtesting = substr($val,0,4);
if($idtesting==1004)
{ $shipping=0.00;
}
if($idtesting==1005)
{ $shipping=0.00;
}
elseif($shipping<15.00){
  $shipping=15.00;
  }
  else $shipping=0.1*$total;

 $subtot=number_format($total,2);

$email.="Subtotal: $" . $subtot . "\n";

 $tax='0.00';
 if($_POST['s_state']=='NM'){
  $tax=number_format($total*0.06500,2) ;
 }
 $shipping=number_format($shipping1,2);

 if($_POST['s_state']=='NM'){
  $t= (($total*1.06500)+($shipping1));
 }else{
  $t= $total+$shipping1;
 }
 $total=number_format($t,2);
 

$email.="Tax: $" . $tax . "\n";
$email.="Shipping: $" . $shipping . "\n";
$email.="Total: $" . $total . "\n";
$email.="\n\n\n";

$email.="Your shipping information:\n\n";
$email.="First name:" .$_POST['s_fname'] . "\n";
$email.="Last name:".$_POST['s_lname'] . "\n";
$email.="Address:".$_POST['s_address'] . "\n";
$email.="City:".$_POST['s_city'] . "\n";
$email.="State:".$_POST['s_state'] . "\n";
$email.="Zip:".$_POST['s_zip'] . "\n";
$email.="Country:".$_POST['s_country'] . "\n";
$email.="Email:".$_POST['s_email'] . "\n";
$email.="Phone:".$_POST['s_phone'] . "\n";
$email.="Fax:".$_POST['s_fax'] . "\n";
$email.="Comment:".$_POST['s_comments'] . "\n";
$email.="\n\n\n";

$email.="Your billing information:\n\n";
$email.="First name:" .$_POST['b_fname'] . "\n";
$email.="Last name:".$_POST['b_lname'] . "\n";
$email.="Address:".$_POST['b_address'] . "\n";
$email.="City:".$_POST['b_city'] . "\n";
$email.="State:".$_POST['b_state'] . "\n";
$email.="Zip:".$_POST['b_zip'] . "\n";
$email.="Country:".$_POST['b_country'] . "\n";

/* let us know what happens with mail() */
/*error_reporting(2047);*/

/* The following wasn't working so I replaced it with the script from crystaltech
   i had to add the ip address 216.119.112.134 to 
   /etc/mail/relay-domains on mail.gigablast.com and restart sendmail 
   ini_set('SMTP','mail.gigablast.com');
*/
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","smtp.gmail.com");

// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");

// Please specify the return address to use
ini_set('sendmail_from', 'jezebel@jezebelgallery.com');

$admin=$email;
/*
$admin.="Credit card information:\n\n";
$admin.="Card type:" . $_POST['card_type'] . "\n";
$admin.="Card expiration(mm/yy):" . $_POST['card_exp_m'] . "/" .  $_POST['card_exp_y'] . "\n";
$admin.="Name on card:" . $_POST['card_name']  . "\n";
$admin.="Card number:" . $_POST['card_num']  . "\n";
$admin.="Card security code:" . $_POST['card_sec']  . "\n";
*/
$subject = "jezebelgallery.com order confirmation";


/*process order*/
//process credit card
		$request=array();
        $request["x_Login"] = "1jezebel";
//        $request["x_Password"] = "Password obscured for my protection";
	    $request["x_tran_key"] = "obscured for my protection";
        $request["x_Version"] = "3.0";
        $request["x_ADC_Delim_Data"] = "TRUE";
        $request["x_ADC_URL"] = "FALSE";
        $request["x_invoice_num"] = $unique_orderid;
        $request["x_cust_id"] = $unique_orderid;		
        $request["x_Card_Num"] =   $_POST['card_num'];
		$request["x_Card_Code"]= $_POST['card_sec'];
        $request["x_Exp_Date"] = $_POST['card_exp_m'] . "20" . $_POST['card_exp_y'];
        $request["x_Amount"] = $t;

        $request["x_First_Name"] = $_POST['b_fname'];
        $request["x_Last_Name"] = $_POST['b_lname'];
        $request["x_Address"] = $_POST['b_address'];
        $request["x_City"] = $_POST['b_city'];
        $request["x_State"] = $_POST['b_state'];
        $request["x_country"] = $_POST['b_country'];		
        $request["x_ZIP"] = $_POST['b_zip'];

        $request["x_ship_to_first_name"] = $_POST['s_fname'];
        $request["x_ship_to_Last_Name"] = $_POST['s_lname'];
        $request["x_ship_to_Address"] = $_POST['s_address'];
        $request["x_ship_to_City"] = $_POST['s_city'];
        $request["x_ship_to_State"] = $_POST['s_state'];
        $request["x_ship_to_country"] = $_POST['s_country'];		
        $request["x_ship_to_ZIP"] = $_POST['s_zip'];
		
        $request["x_Phone"] = $_POST['s_phone'];
        $request["x_fax"] = $_POST['s_fax'];		
        $request["x_Email"] = $_POST['s_email'];  
        //$request["x_merchant_email"] = "mickel@jezebelgallery.com";
	$request["x_merchant_email"] = "jezebel@jezebelgallery.com";

        $posturl = "https://secure.authorize.net/gateway/transact.dll?";

        $ch = new COM("MSXML2.ServerXMLHTTP"); // initalize COM Object

        // take the $request array and turn it into name=value&name=value pairs
        if (count($request) > 0) {
                reset($request);
                while (list($name, $value) = each($request)) {
                        $str .= "&".$name."=".$value;
                }
                $str = substr($str,1);
        }

/* Comment out for testing do not send data to credit card processor */
        $ch->open("POST", $posturl, false);
        $ch->setRequestHeader("User-Agent", "AUTH-PHP-API (OnlineCreator)");
        $ch->setRequestHeader("Content-Type", "application/x-www-form-urlencoded");     
        $ch->send($str);
        $results = $ch->responseText; // connect and grab the results
        //$ch->Release();
        $ch = null;
		//1 = accepted, 2 = declined, 3 = error         
        $rescode = substr($results,0,1);
		$rrc = substr($results,2,3);
        if(substr($results,0,1)=="1"){
		 /*if("1"=="1"){*/ //for testing
		 $message="Thank you for your order. A confirmation email has been sent to " . $_POST['s_email'];
		 /* To send HTML mail, you can set the Content-type header. */
		 $headers  = "MIME-Version: 1.0\r\n";
		 $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
		 //$headers .= "From: jezebel@jezebelgallery.com\r\n";
		 $headers .= "From: jezebel@jezebelgallery.com\r\n";
		 //New lines suggested by crystaltech
         $_Timestamp = date("r");
         $headers = "Date: $_Timestamp";

		 $email=str_replace("\n","<br>",$email);

// the next line is for testing
//		 echo "$to $subject <html> $email </html> $headers";

// Send confirmation to person ordering
		 $to=$_POST['s_email'];
		 mail($to, $subject, "<html>" . $email . "</html>", $headers);

		 //$to = 'jezebel@jezebelgallery.com';
		 //$to = 'cynthia@immediagroup.com';
		 //$subject = "jezebelgallery.com order confirmation";
		 //mail($to, $subject, $admin, $headers);

		 //$to = 'mickel@jezebelgallery.com';
/*
		 $to = 'jezebel@jezebelgallery.com';
*/ 


// this will send confirmations to jezebel accounts activate for final update
    $to='jezebel@jezebelgallery.com,sales@jezebelgallery.com';
	mail($to, $subject, "<html>" . $email . "</html>",$headers);
		 
		 unset($_SESSION['cart']);
		}else{
		 $message="Your credit card could not be processed. Go <a href='javascript: history.go(-1)'>back</a> and make sure that all your information is correct. Full Result=" . $results;
 		 /*
		 foreach($request as $a => $b){ echo "$a $b <br>";}
		 echo $results; */
		}
 // Send a copy of each order to webmaster during testing phase whether or not accepted.
    $to='brucemcintosh@gmail.com';
	//comment out next line when testing activate when testing done
    $email='Order Placed';   
    $subject=$message;
	mail($to, $subject, "<html>" . $email . "</html>",$headers);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Jezebel Gallery - Shopping Cart</title>
<meta name="author" content="dreamLogic">
<meta name="Description" content="Gallery of Santa Fe artist, painter and sculptor Jezebel.  Features one-of-a-kind stained glass lighting and home accessories.">
<meta name="Keywords" content="gallery, artist, painting, scupture, home, decor, accessories, lighting, lamps, chandeliers, sconce, custom, creative, furnishings, jewelry, santa fe, albuquerque, new mexico, nm">
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//-->
</script>
<link rel="stylesheet" href="newstyle.css" type="text/css">
<script src="rollovers.js" type="text/javascript"></script>
</head>


<body>

<!-- Customization Code -->
<!-- Remove leading // to activate custom variables -->
<script language="Javascript">
//var DOCUMENTGROUP='';
var DOCUMENTNAME='Sale';
var ACTION='01';
</script>
<!-- End of Customization Code -->
<!-- Tracking Code v3.01 - All rights reserved -->
<script language="javascript1.1" src="http://www.jezebelgallery.com/tracking.js"></script><noscript>
<img src="http://webstats.silverscopepromotion.com/p.pl?a=1000638354890&js=no" width="1" height="1"></noscript><!--//-->
<!-- End of Tracking Code -->
<p class="style3">Jezebel Gallery &raquo; Order Complete </p>
            
<?= $message ?>

                        </td>
                    </tr>
                  </table>
                  



<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-6579606-1");
pageTracker._trackPageview();
} catch(err) {}</script>
</body>
</html>
<?                
/* Closing connection */
mysql_close($link);
//session_destroy();            
?>  
I did the error reporting and the following lines show up.

Notice: Undefined index: post_vars
Notice: Undefined index: cart
Notice: Undefined index: cart
Notice: Undefined index: discount
Notice: Undefined variable: val
Notice: Undefined variable: shipping
Notice: Undefined variable: total
Notice: Undefined variable: shipping1
Notice: Undefined variable: shipping1
Notice: Undefined variable: total
Notice: Undefined variable: str
Notice: Undefined variable:
Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. f5sm2922557wfo.4 on line 305

keep in mind I use google apps for my e-mail and the line in question is:

mail($to, $subject, "<html>" . $email . "</html>",$headers);

any suggestions? And what's weird is the undefined variables didn't have a problem back when this was PHP4. What should I do about this?

Apparently the last Warning requires me to change the php.ini settings somehow. Any ideas?
Post Reply