Jump to content

Some help with this code please


roldahayes
Go to solution Solved by ginerjm,

Recommended Posts

Hi, please can you have a look at this code.

 

It is a receipt page for a checkout and it automatically emails both the customer and myself the order details.

 

it all works well apart from on the email that is sent to me, there is no DELIVERY DETAILS.

 

All of the customer billing is sent, and the items that they have ordered, I just cannot get the delivery to send as well....

 

Is there anything obvious that I am missing that could be causing this?

 

Thanks,

 

<?phpinclude_once("func_lib.php"); // use the user_connection include file's connectDB functioninclude_once("usr_conn.php");if(!connectDB()){echo "<p>Unable To Connect To Database</p>";return;}    // assign variables$currency = "£"; //get confirmation or customerID etc$userID = stripslashes(($_COOKIE['userID'] ? $_COOKIE['userID'] : str_replace("BR_", "", $_GET["oid"])));$shopperID = stripslashes(substr($userID, 0, 6)); $token = md5(uniqid(rand(),1));setcookie("userID", $token, time() + 3600, "/");setcookie("userID", $token, time() + 3600, "/upload/");//echo "userID = ".$_COOKIE['userID'];  //get the user details$result = mysql_query("SELECT * FROM shopper WHERE User_ID='$userID'");$UserDetails = mysql_fetch_assoc($result); $custdetails = explode("\n",$UserDetails["Customer_Address"]);foreach($custdetails as $value) {if(strpos($value,"Customer_Email") !== false) { $Customer_Email = str_replace("Customer_Email = ", "", $value); }}  //check that the order has not alerady been sentif (isset ($_COOKIE['order'])){$message = "Your order has already been processed";$blnSet = "1"; } ?>   <?php  //get info from shopper table$sqlquery = "SELECT * FROM shopper WHERE user_ID = '" . $userID . "'";$result = mysql_query($sqlquery);echo '<!--'.mysql_error() .'-->';$rowCount = mysql_num_rows($result);echo'<!--test-->';// if no matches then nothing to checkoutif ($rowCount == 0){echo'<!--in-->';echo ("<p><font class=error>Your basket was empty. You have come to this page in error!!<br>Please return to the main site</font></p>");return;}else{ //store shopper details$shoprow = mysql_fetch_assoc($result);$Basket_total = number_format(htmlspecialchars($shoprow['Basket_total']), 2);$Post_type = htmlspecialchars($shoprow['Postage']);//echo "tot: " . $Basket_total;$Postage = htmlspecialchars($shoprow['Postage']);//get basket details$sqlquery = "SELECT * FROM basket WHERE userID = '" . $userID . "'";$result = mysql_query($sqlquery);$rowCount = mysql_num_rows($result);if ($rowCount == 0){echo "<font class=error><p>Error: Your basket was empty.</p></font>";return;}else{// select the userID's basket query and the Product Reference relating to each of the basket's productID's$sqlquery = "SELECT * FROM basket INNER JOIN products ON basket.productID = products.Prod_ID WHERE ((basket.userID) = '" . $userID . "')";//echo $sqlquery;$baskresult = mysql_query($sqlquery);$rowCount = mysql_num_rows($baskresult); //set counter to name each hidden form element for the product details$frmCount = 1; while ($row = mysql_fetch_assoc($baskresult)){ //cut the prod_type variable//get the length of the variable$strLength = strlen ($row["Prod_Type"]);//assign first 2 characters of variable$strPrefix = substr($row["Prod_Type"], 0, 2);//debug//echo "\n prefix :" . $strPrefix;//assign remaining characters of variable$strSuffix = substr($row["Prod_Type"], 2, $strLength);//debug//echo "\n suffix :" . $strSuffix; //set product header image depending on the Prod_Type Code//start the table row$strProdType = prodType ($strPrefix);  echo("<tr class=stdtable><td align=center> " . htmlspecialchars($row['Car_Make']) . " " . "</td>");echo("<td align=center> " . $strProdType . " " . "</td>");echo("<td align=center> " . htmlspecialchars($row['Prod_Make']) . "<br>" . htmlspecialchars($row['Product_Desc']) . "</td>");echo("<td align=center> " . htmlspecialchars($row['Prod_REF']) . " " . "</td>");echo("<td align=center>". htmlspecialchars($row['quantity']) ."</td></tr>");//create hidden form names and values containing product detailsecho "<input type=hidden name=Product".$frmCount."_Make value=\"". htmlspecialchars($row['Prod_Make']) ."\">";echo "<input type=hidden name=Product".$frmCount."_Model value=\"". htmlspecialchars($row['Prod_Model']) ."\">";echo "<input type=hidden name=Product".$frmCount."_Type value=\"". $strProdType ."\">";echo "<input type=hidden name=Product".$frmCount."_REF value=\"". $row['Prod_REF'] ."\">";echo "<input type=hidden name=Product".$frmCount."_Quantity value=\"". htmlspecialchars($row['quantity']) ."\">";//incrementcount by 1$frmCount ++;}//end while echo("<tr class=stdtable><td colspan=3> </td><td align=center><b>TOTAL</b></td><td align=center>" . $currency . $Basket_total . "</td></tr>"); }//end else}//end else?>                                                   Number = <?php echo $shopperID; ?> </td>                                 <?php   if ($UserDetails["Success"] == 1){ } echo ("Your order has been placed successfully. We will email or call you shortly confirming your details. <br><br>Thank you for visiting.");  ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //THIS IS THE EMAIL TO US //get info from shopper table$sqlquery = "SELECT * FROM shopper WHERE user_ID = '" . $userID . "'";$result = mysql_query($sqlquery);$rowCount = mysql_num_rows($result);  { //store shopper details$shoprow = mysql_fetch_assoc($result);$Basket_total = number_format(htmlspecialchars($shoprow['Basket_total']), 2);$Post_type = htmlspecialchars($shoprow['Postage']);$Postage = htmlspecialchars($shoprow['Postage']);$custdetails = explode("\n",$shoprow["Customer_Address"]); foreach($custdetails as $value) {if(strpos($value,"Customer_Name") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_Surname") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Business_name") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_Address") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_Town") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_County") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_Postcode") !== false) { $Additional_Details .= "$value\n"; } if(strpos($value,"Customer_Tel") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_Mobile") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_Email") !== false) { $Additional_Details .= "$value\n"; }    if(strpos($value,"Delivery_Firstname") !== false) { $Delivery_Details .= "$value\n"; }if(strpos($value,"Delivery_Surname") !== false) { $Delivery_Details .= "$value\n"; }if(strpos($value,"Delivery_Busienssname") !== false) { $Delivery_Details .= "$value\n"; }if(strpos($value,"Delivery_Address1") !== false) { $Delivery_Details .= "$value\n"; }if(strpos($value,"Delivery_Address2") !== false) { $Delivery_Details .= "$value\n"; }if(strpos($value,"Delivery_Town") !== false) { $Delivery_Details .= "$value\n"; }if(strpos($value,"Delivery_County") !== false) { $Delivery_Details .= "$value\n"; }if(strpos($value,"Delivery_Postcode") !== false) { $Delivery_Details .= "$value\n"; } if(strpos($value,"Delivery_Instructions") !== false) { $Delivery_Details .= "$value\n"; }    }  //get basket details$sqlquery = "SELECT * FROM basket WHERE userID = '" . $userID . "'";$result = mysql_query($sqlquery);$rowCount = mysql_num_rows($result);if ($rowCount == 0){echo "<font class=error><p>Error: Your basket was empty.</p></font>";return;}else{// select the userID's basket query and the Product Reference relating to each of the basket's productID's$sqlquery = "SELECT * FROM basket INNER JOIN products ON basket.productID = products.Prod_ID WHERE ((basket.userID) = '" . $userID . "')";//echo $sqlquery;$baskresult = mysql_query($sqlquery);$rowCount = mysql_num_rows($baskresult); //set counter to name each hidden form element for the product details$frmCount = 1; $strBody = "Order Details are as follows\n\n";$strBody = $strBody . "ShopperID : ".$shopperID."\n\n";$strBody = $shoprow["Customer_Address"]."\n\n";//get alternate delivery details$strBody = $shoprow["Delivery_Address"]."\n\n";$strBody = $shoprow["Search_Engine"]."\n\n";while ($row = mysql_fetch_assoc($baskresult)){ //cut the prod_type variable//get the length of the variable$strLength = strlen ($row["Prod_Type"]);//assign first 2 characters of variable$strPrefix = substr($row["Prod_Type"], 0, 2);//debug//echo "\n prefix :" . $strPrefix;//assign remaining characters of variable$strSuffix = substr($row["Prod_Type"], 2, $strLength);//debug//echo "\n suffix :" . $strSuffix;   //set product header image depending on the Prod_Type Code//start the table row$strProdType = prodType ($strPrefix); $strBody = $strBody ."Order : ".$frmCount;$strBody = $strBody ."\nCarmake : ".htmlspecialchars($row['Car_Make']);$strBody = $strBody ."\nProduct Type : ".$strProdType;$strBody = $strBody ."\nProduct Make : ".htmlspecialchars($row['Prod_Make']);$strBody = $strBody ."\nProduct Model : ".htmlspecialchars($row['Prod_Model']);$strBody = $strBody ."\nProduct Description : ".htmlspecialchars($row['Product_Desc']);$strBody = $strBody ."\nProduct reference : ".htmlspecialchars($row['Prod_REF']);$strBody = $strBody ."\nQuantity : ".htmlspecialchars($row['quantity']);$strBody = $strBody ."\nProduct Price : ".number_format(calcVAT(htmlspecialchars($row['Price_ExVat'])), 2);$strBody = $strBody ."\n"."End of order ".$frmCount."\n\n";$frmCount ++; }//end while $strBody = $strBody .$Additional_Details."\n\n"; $strBody = $strBody .$Delivery_Details."\n\n";$strBody = $strBody ."Postage rate is ".$Postage."\n";$strBody = $strBody ."\n\nTotal : ".$currency . $Basket_total; }//end else}//end else   // set up mail details$mail_to = "mail@mail.com";$mail_from = stripslashes($Customer_Email);$mail_subject = "ORDER PAYPAL";$mail_headers = "FROM: $mail_from\r\n";//added additional recipient$mail_body = $strBody;   //create mail footer message  //concatinate mail_body and mail_footer$mail_body = $mail_body . $mail_footer;// send mailif (mail($mail_to, $mail_subject, $mail_body, $mail_headers)) {//echo ("<p>Message sent</p>");} else {echo ("<p>Error On Sending Mail</p>");} /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////?>                  <?php$blnSet = "";?>   <?php// THIS IS THE EMAIL TO THE CUSTOMER// set up mail details$mail_to = stripslashes($Customer_Email);$mail_from = "mail@mail.com";$mail_subject = "Order Confirmation";$mail_headers = "FROM: $mail_from\r\n"; //added additional recipient$mail_body = "Dear Customer,\n\nYour order has been sent to us successfully and you should have printed the order confirmation page. If you do not have a copy, please make a note of the following ShopperID :- ".$shopperID.".";   //concatinate mail_body and mail_footer$mail_body = $mail_body . $mail_footer;// send mailif (mail($mail_to, $mail_subject, $mail_body, $mail_headers)) {//echo ("<p>Message sent</p>");} else {echo ("<p>Error On Sending Mail</p>");} ?> 

Link to comment
Share on other sites

I don't see anything that stands out as a problem other than a misspelling on this line for the word "business"

if(strpos($value,"Delivery_Busienssname") !== false) { $Delivery_Details .= "$value\n"; }

Have you actually done a print_r() on $custdetails to make sure it even has any of the delivery details in the list?  Seems pretty weird that all the customer info and delivery address info is in one row of the DB, all those details are usually in separate columns in the DB.

Link to comment
Share on other sites

It looks like the billing is in  Customer_Details and the delivery info is in Delivery_Details.

 

Would this need to be edited to import both colums in the output?

 

 

$custdetails = explode("\n",$UserDetails["Customer_Address"]);

Edited by roldahayes
Link to comment
Share on other sites

I've nearly got this working....

 

It is now sending the customer and delivery details but each line is jumbled up...?  They are not showing in 2 separate blocks on the email.

 

 <?php//include header code//include_once("head.php");//include header codeinclude_once("func_lib.php"); // use the user_connection include file's connectDB functioninclude_once("usr_conn.php");if(!connectDB()){echo "<p>Unable To Connect To Database</p>";return;}// assign variables$currency = "£"; //get confirmation or customerID etc$userID = stripslashes(($_COOKIE['userID'] ? $_COOKIE['userID'] : str_replace("AR_", "", $_GET["oid"])));$shopperID = stripslashes(substr($userID, 0, 6)); $token = md5(uniqid(rand(),1));setcookie("userID", $token, time() + 3600, "/");setcookie("userID", $token, time() + 3600, "/upload/");//echo "userID = ".$_COOKIE['userID']; //get the user details$result = mysql_query("SELECT * FROM shopper WHERE User_ID='$userID'");$UserDetails = mysql_fetch_assoc($result); $UserDelDetails = mysql_fetch_assoc($result); // NEW LINE $custdetails = explode("\n",$UserDetails["Customer_Address"]);foreach($custdetails as $value) {if(strpos($value,"Customer_Email") !== false) { $Customer_Email = str_replace("Customer_Email = ", "", $value); }}    $Deldetails = explode("\n",$UserDelDetails["Customer_Address"]);  //NEW LINESforeach($Deldetails as $value) {if(strpos($value,"Delivery_Email") !== false) { $Delivery_Email = str_replace("Delivery_Email = ", "", $value); }}    //check that the order has not alerady been sentif (isset ($_COOKIE['order'])){$message = "Your order has already been processed";$blnSet = "1"; } ?>   <?php  //get info from shopper table$sqlquery = "SELECT * FROM shopper WHERE user_ID = '" . $userID . "'";$result = mysql_query($sqlquery);echo '<!--'.mysql_error() .'-->';$rowCount = mysql_num_rows($result);echo'<!--test-->';// if no matches then nothing to checkoutif ($rowCount == 0){echo'<!--in-->';echo ("<p><font class=error>Your basket was empty. You have come to this page in error!!<br>Please return to the main site</font></p>");return;}else{ //store shopper details$shoprow = mysql_fetch_assoc($result);$Basket_total = number_format(htmlspecialchars($shoprow['Basket_total']), 2);$Post_type = htmlspecialchars($shoprow['Postage']);//echo "tot: " . $Basket_total;$Postage = htmlspecialchars($shoprow['Postage']);//get basket details$sqlquery = "SELECT * FROM basket WHERE userID = '" . $userID . "'";$result = mysql_query($sqlquery);$rowCount = mysql_num_rows($result);if ($rowCount == 0){echo "<font class=error><p>Error: Your basket was empty.</p></font>";return;}else{// select the userID's basket query and the Product Reference relating to each of the basket's productID's$sqlquery = "SELECT * FROM basket INNER JOIN products ON basket.productID = products.Prod_ID WHERE ((basket.userID) = '" . $userID . "')";//echo $sqlquery;$baskresult = mysql_query($sqlquery);$rowCount = mysql_num_rows($baskresult); //set counter to name each hidden form element for the product details$frmCount = 1; while ($row = mysql_fetch_assoc($baskresult)){ //cut the prod_type variable//get the length of the variable$strLength = strlen ($row["Prod_Type"]);//assign first 2 characters of variable$strPrefix = substr($row["Prod_Type"], 0, 2);//debug//echo "\n prefix :" . $strPrefix;//assign remaining characters of variable$strSuffix = substr($row["Prod_Type"], 2, $strLength);//debug//echo "\n suffix :" . $strSuffix; //set product header image depending on the Prod_Type Code//start the table row$strProdType = prodType ($strPrefix);  echo("<tr class=stdtable><td align=center> " . htmlspecialchars($row['Car_Make']) . " " . "</td>");echo("<td align=center> " . $strProdType . " " . "</td>");echo("<td align=center> " . htmlspecialchars($row['Prod_Make']) . "<br>" . htmlspecialchars($row['Product_Desc']) . "</td>");echo("<td align=center> " . htmlspecialchars($row['Prod_REF']) . " " . "</td>");echo("<td align=center>". htmlspecialchars($row['quantity']) ."</td></tr>");//create hidden form names and values containing product detailsecho "<input type=hidden name=Product".$frmCount."_Make value=\"". htmlspecialchars($row['Prod_Make']) ."\">";echo "<input type=hidden name=Product".$frmCount."_Model value=\"". htmlspecialchars($row['Prod_Model']) ."\">";echo "<input type=hidden name=Product".$frmCount."_Type value=\"". $strProdType ."\">";echo "<input type=hidden name=Product".$frmCount."_REF value=\"". $row['Prod_REF'] ."\">";echo "<input type=hidden name=Product".$frmCount."_Quantity value=\"". htmlspecialchars($row['quantity']) ."\">";//incrementcount by 1$frmCount ++;}//end while echo("<tr class=stdtable><td colspan=3> </td><td align=center><b>TOTAL</b></td><td align=center>" . $currency . $Basket_total . "</td></tr>"); }//end else}//end else?>                                                Number = <?php echo $shopperID; ?> </td>                                <?php //create messsage based on whether mail was sent or not if ($UserDetails["Success"] == 1){//finally send out a confirmation email to the customer, including their ShopperID } echo ("Your order has been placed successfully. We will email or call you shortly confirming your details. <br><br>Thank you for visiting.");  //get info from shopper table$sqlquery = "SELECT * FROM shopper WHERE user_ID = '" . $userID . "'";$result = mysql_query($sqlquery);$rowCount = mysql_num_rows($result);  { //store shopper details$shoprow = mysql_fetch_assoc($result);$Basket_total = number_format(htmlspecialchars($shoprow['Basket_total']), 2);$Post_type = htmlspecialchars($shoprow['Postage']);$Postage = htmlspecialchars($shoprow['Postage']);$custdetails = explode("\n",$shoprow["Customer_Address"]);foreach($custdetails as $value) {   if(strpos($value,"Customer_Name") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_Surname") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Business_name") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_Address") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_Town") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_County") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_Postcode") !== false) { $Additional_Details .= "$value\n"; } if(strpos($value,"Customer_Tel") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_Mobile") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Customer_Email") !== false) { $Additional_Details .= "$value\n"; }  $Deldetails = explode("\n",$shoprow["Delivery_Address"]);foreach($Deldetails as $value) { if(strpos($value,"Delivery_Firstname") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Delivery_Surname") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Delivery_Busienssname") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Delivery_Address1") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Delivery_Address2") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Delivery_Town") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Delivery_County") !== false) { $Additional_Details .= "$value\n"; }if(strpos($value,"Delivery_Postcode") !== false) { $Additional_Details .= "$value\n"; } if(strpos($value,"Delivery_Instructions") !== false) { $Additional_Details .= "$value\n"; }  }   //get basket details$sqlquery = "SELECT * FROM basket WHERE userID = '" . $userID . "'";$result = mysql_query($sqlquery);$rowCount = mysql_num_rows($result);if ($rowCount == 0){echo "<font class=error><p>Error: Your basket was empty.</p></font>";return;}else{// select the userID's basket query and the Product Reference relating to each of the basket's productID's$sqlquery = "SELECT * FROM basket INNER JOIN products ON basket.productID = products.Prod_ID WHERE ((basket.userID) = '" . $userID . "')";//echo $sqlquery;$baskresult = mysql_query($sqlquery);$rowCount = mysql_num_rows($baskresult); //set counter to name each hidden form element for the product details$frmCount = 1; $strBody = "Order Details are as follows\n\n";$strBody = $strBody . "ShopperID : ".$shopperID."\n\n";$strBody = $shoprow["Customer_Address"]."\n\n";//get alternate delivery details$strBody = $shoprow["Delivery_Address"]."\n\n";$strBody = $shoprow["Search_Engine"]."\n\n";while ($row = mysql_fetch_assoc($baskresult)){ //cut the prod_type variable//get the length of the variable$strLength = strlen ($row["Prod_Type"]);//assign first 2 characters of variable$strPrefix = substr($row["Prod_Type"], 0, 2);//debug//echo "\n prefix :" . $strPrefix;//assign remaining characters of variable$strSuffix = substr($row["Prod_Type"], 2, $strLength);//debug//echo "\n suffix :" . $strSuffix;   //set product header image depending on the Prod_Type Code//start the table row$strProdType = prodType ($strPrefix); $strBody = $strBody ."Order : ".$frmCount;$strBody = $strBody ."\nCarmake : ".htmlspecialchars($row['Car_Make']);$strBody = $strBody ."\nProduct Type : ".$strProdType;$strBody = $strBody ."\nProduct Make : ".htmlspecialchars($row['Prod_Make']);$strBody = $strBody ."\nProduct Description : ".htmlspecialchars($row['Product_Desc']);$strBody = $strBody ."\nProduct reference : ".htmlspecialchars($row['Prod_REF']);$strBody = $strBody ."\nQuantity : ".htmlspecialchars($row['quantity']);$strBody = $strBody ."\nProduct Price : ".number_format(calcVAT(htmlspecialchars($row['Price_ExVat'])), 2);$strBody = $strBody ."\n"."End of order ".$frmCount."\n\n";$frmCount ++; }//end while $strBody = $strBody .$Additional_Details."\n\n";$strBody = $strBody ."Postage rate is ".$Postage."\n";$strBody = $strBody ."\n\nTotal : ".$currency . $Basket_total; }//end else}//end else }//end what every I have done! // set up mail details$mail_to = "mail@mail.com";//info@autorack.co.uk$mail_from = stripslashes($Customer_Email);$mail_subject = "Order Confirmation";$mail_headers = "FROM: $mail_from\r\n";//added additional recipient$mail_body = $strBody;     //concatinate mail_body and mail_footer$mail_body = $mail_body . $mail_footer;// send mailif (mail($mail_to, $mail_subject, $mail_body, $mail_headers)) {//echo ("<p>Message sent</p>");} else {echo ("<p>Error On Sending Mail</p>");} ?>        <?php //include footer code ?>  <?php$blnSet = "";?>   <?php // set up mail details$mail_to = stripslashes($Customer_Email);$mail_from = "mai@mail.com";$mail_subject = "Your Order Confirmation";$mail_headers = "FROM: $mail_from\r\n"; //added additional recipient$mail_body = "Dear Customer,\n\nYour order has been sent to us successfully and you should have printed the order confirmation page. If you do not have a copy, please make a note of the following ShopperID :- ".$shopperID.". You may refer to this if you have any queries.\n\nWe will contact you to confirm your order.".  //create mail footer message  //concatinate mail_body and mail_footer$mail_body = $mail_body . $mail_footer;// send mailif (mail($mail_to, $mail_subject, $mail_body, $mail_headers)) {//echo ("<p>Message sent</p>");} else {echo ("<p>Error On Sending Mail</p>");} ?> 

Link to comment
Share on other sites

This is how the mail is printing:
It is also repeating the headings a few times!
 
 
 
 
Order : 1
Carmake : n/a
Product Type : asd

Product Make : asd
Product Description : Stand
Product reference : 2DH
Quantity : 1
Product Price : 23.95

End of order 1

Customer_Name = asd

Delivery_Firstname = asd
Delivery_Surname = asd
Delivery_Address1 = asd
Delivery_Address2 = asd
Delivery_Town = asd
Delivery_County = asd
Delivery_Postcode = asd
Customer_Surname = asd
Delivery_Firstname = asd
Delivery_Surname = asd
Delivery_Address1 = asd
Delivery_Address2 = asd
Delivery_Town = asd
Delivery_County = asd
Delivery_Postcode = asd

Business_name = asd

Delivery_Firstname = asd
Delivery_Surname = asd
Delivery_Address1 = asd
Delivery_Address2 = asd
Delivery_Town = asd
Delivery_County = asd
Delivery_Postcode = asd

Customer_Address1 =  asd

Delivery_Firstname = asd
Delivery_Surname = asd
Delivery_Address1 = asd
Delivery_Address2 = asd
Delivery_Town = asd
Delivery_County = asd
Delivery_Postcode = asd
Customer_Address2 = asd
Delivery_Firstname = asd
Delivery_Surname = asd
Delivery_Address1 = asd
Delivery_Address2 = asd
Delivery_Town = asd
Delivery_County = asd
Delivery_Postcode = asd
Customer_Town = asd
Delivery_Firstname = asd
Delivery_Surname = asd
Delivery_Address1 = asd
Delivery_Address2 = asd
Delivery_Town = asd
Delivery_County = asd
Delivery_Postcode = asd
Customer_County = asd
Delivery_Firstname = asd
Delivery_Surname = asd
Delivery_Address1 = asd
Delivery_Address2 = asd
Delivery_Town = asd
Delivery_County = asd
Delivery_Postcode = asd
Customer_Postcode = asd
Delivery_Firstname = asd
Delivery_Surname = asd
Delivery_Address1 = asd
Delivery_Address2 = asd
Delivery_Town = asd
Delivery_County = asd
Delivery_Postcode = asd
Customer_Email = mail@mail.com
Delivery_Firstname = asd
Delivery_Surname = asd
Delivery_Address1 = asd
Delivery_Address2 = asd
Delivery_Town = asd
Delivery_County = asd
Delivery_Postcode = asd
Customer_Tel = 23456
Delivery_Firstname = asd
Delivery_Surname = asd
Delivery_Address1 = asd
Delivery_Address2 = asd
Delivery_Town = asd
Delivery_County = asd
Delivery_Postcode = asd
Customer_Mobile = 23456
Delivery_Firstname = asd
Delivery_Surname = asd
Delivery_Address1 = asd
Delivery_Address2 = asd
Delivery_Town = asd
Delivery_County = asd
Delivery_Postcode = asd


Postage rate is 0


Total : £31.90

Link to comment
Share on other sites

Sorry - but I don't call what you posted "jumbled up".  It looks perfectly normal to me.  Is this supposed to be in some special format?  From what I can tell from your verrrry lengthy post this is what you expected.  What did you have in mind?

Link to comment
Share on other sites

Its supposed to have all of the "Customer" details listed first, then the "Delivery" details.

 

This has the delivery section repeated 11 times.....  it should read something like:

 

 

Customer_Firstname = asd
Customer_Surname = asd
Customer_Address1 = asd
Customer_Address2 = asd
Customer_Town = asd
Customer_County = asd
Customer_Postcode = asd

 

Delivery_Firstname = asd
Delivery_Surname = asd
Delivery_Address1 = asd
Delivery_Address2 = asd
Delivery_Town = asd
Delivery_County = asd
Delivery_Postcode = asd

Link to comment
Share on other sites

Can you post a print_r($UserDetails); here so we can see what your query is returning.  As I said before, it seems your db structure and storage method is flawed and probably causing all this headache.  Please make sure to post the result in a readable manner, usually best to take the display from the "view source" of the browser so that it is formatted better.

Link to comment
Share on other sites

OK. Viewing the source of this appears as it should.  I't seems just the email body is incorrect.


Array   (   [user_ID] => 26fd3a48dcf0f5565b81730fe9177e47   [basket_total] => 92.90   [Postage] => 0   [CardRef] =>   [Customer_Address] => Customer_Name = JOHN   Customer_Surname = SMITH   Business_name = SMITH & CO   Customer_Address1 = 25 ORCHARD STREET   Customer_Address2 = LITTLE VILLAGE   Customer_Town = LONDON   Customer_County = Bucks   Customer_Postcode = NE21 9RE   Customer_Email = J@JOHN.COM   Customer_Tel = 123456   Customer_Mobile = 123456   [Delivery_Address] => Delivery_Title = Mr.   Delivery_Firstname = George   Delivery_Surname = JONES   Delivery_Businessname = SMITH & CO   Delivery_Address1 = 123 HIGH STREET   Delivery_Address2 = HACKNEY   Delivery_Town = LONDON   Delivery_County = BUCKS   Delivery_Postcode = NE10 7FD   [search_Engine] =>   [success] =>   [shopping_Basket] =>   Car1_Make = n/a   Car1_Model = not specific   Product1_Make = Thule   Product1_Model = 591   Product1_Type = Bike Rack   Product1_REF = 591   Product1_Quantity = 1   Product1_Price = 84.95       ) Edited by roldahayes
Link to comment
Share on other sites

I know I'm pointing out the obvious, but the email body is built entirely by YOUR code.  No mystery - you just have to look at what you are doing. and correct it. 

The way I would construct the body would be to do this:

$body = (a bunch of header text)

 

then run a loop on my data and do this:

$body .= (data from current row)

$body .= (data from current row)

$body .= (data from current row)

 

After the loop, add the closing comments

 

$body .= (ending text)

 

NOTE the use of the (dot)=  in each of those body statements (except the first).

 

IMHO, all of this detail that you want to display is going to be pretty ugly unless you use an html email and embed it all in an html table in that loop.

Edited by ginerjm
Link to comment
Share on other sites

Ok so half of what you are doing is in a sense wrong or pointless.  As I thought, your db structure and storage is bad.  You really should have a table column for each different data value.  So like delivery city should be it's own column, etc.  That will make life so much easier in the long run.  The way you store the data now makes it very difficult to query against and to effectively use the data once you query it.  As you can see, the explode on \n is just a bad idea and is highly suseptable to misinterpretaion by the script if for some reason a value accidentaly had a extra \n in there or it wasn't stored properly in some way.  But I guess that's all up to you to decide how good you want this to work.

 

But to help with your current problem, you need to change a var on this line

$Deldetails = explode("\n",$UserDelDetails["Customer_Address"]);  //NEW LINES

To

$Deldetails = explode("\n",$UserDelDetails["Delivery_Address"]);  //NEW LINES

Honestly I don't know why you even did this

$UserDelDetails = mysql_fetch_assoc($result); // NEW LINE

Since the line above it has the exact same info already.  Beyond that I don't know what to say, your code you posted has far too much whitespace and line breaks that make it difficult to read through cause it's hard to figure out what code blocks hold what info.  I would take a serious look at your db structure and fix that before moving forward.

Link to comment
Share on other sites

Ah!  a case of seeing wood for the trees!  I hadn't realised that I has not changed that line to "Delivery_Address"  !

 

 

 

 Honestly I don't know why you even did this

Desperation I think....  I was trying anything to make this work!

 

It now prints correctly in 2 paragraphs as I want it but the delivery address section is still repeating itself 11 times??

Edited by roldahayes
Link to comment
Share on other sites

  • Solution

Once again - it is in your code.  If you don't understand how some functions work, either read up on them or don't use them.  Somewhere in your code (and I'm not going to try and understand it again) YOU are outputting the data NOT in the way you think or want to do it. 

 

A good portion of any programmer's life in any language on any platform is spent in figuring out just where he/she went wrong.  Time for you to expend some of that part of your life.

 

Try and simplify your code.  Break it up into distinct parts and make those parts finto unctions.  Fine tune them until they do EXACTLY what you want and then put it all together with one set of code that initializes things, calls the functions to build those things and then outputs those things.  Hate to be blunt like this but you really have to get a handle on what your code is doing and where you are doing it wrong.

Edited by ginerjm
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.