php array to email body.....line saparated

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

walkerwilly77
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Jan 28, 2013 10:04 pm

php array to email body.....line saparated

Postby walkerwilly77 » Mon Jan 28, 2013 10:06 pm

can you one of the php master can help me out with this


this is my array output

Array ( [0] => WI BLACK CHERRY BASE [1] => 1 [2] => WI STRAWBERRY BASE [3] => 1 )



this is the buttom I am using to past the value


<form id="form1" name="form1" method="post" action="/storescripts/mailcart.php">
<input type="hidden" name="message" id="message" value="<?php echo $mail_id_array; ?>" />
<input type="submit" name="button" id="button" value="Send Order" />
</form>



this is the mailcart.php

<?php
$message = '';
$name = "wesrt";
$email = "abc@hotmail.com";
$message .= $_POST[message];
$formcontent=" From: $name \n Message: $message";
$recipient = "info@xsn.com";
$subject = "Order Form";
$mailheader = "From: $email \r\n";
//mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
mail($recipient, $subject, $message, $mailheader) or die("Error!");
print_r($message);
//header( 'Location: http://www.xsn.com/index.php' ) ;
//echo "Thank You!";

?>


I am getting this:

WI BLACK CHERRY BASE .--->.1<br>WI STRAWBERRY BASE .--->.1<br>



and I would like to have the following result:


WI BLACK CHERRY BASE .--->.1

WI STRAWBERRY BASE .--->.1

walkerwilly77
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Jan 28, 2013 10:04 pm

Re: php array to email body.....line saparated

Postby walkerwilly77 » Tue Jan 29, 2013 11:15 am

i was not 100 explanatory in my last post I am new at all this forum staff, here it is the long history

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//this is my cart page cart.php here I do render my dynamic cart table wich is the values i want to have in my email body separated in diferent lines
//I delete some of the top code because i do not want to give you innecessary code to read but workss
//in the html body you will find the buttom I do use to send the value to my cartemail.php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


<?php
session_start(); // Start session first thing in script
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Connect to the MySQL database
include "storescripts/connect_to_mysql.php";
?>

<?php
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Section 5 (render the cart for the user to view on the page)
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$cartOutput = "";
$cartTotal = "";
$quantity = "";
$pp_checkout_btn = '';
$product_id_array = '';
$mail_id_array = '';
$sentoemail=array();
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
$cartOutput = "<h2 align='center'>Your shopping cart is empty</h2>";
} else {
// Start PayPal Checkout Button
$pp_checkout_btn .= '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="business" value="you@youremail.com">';
// Start the For Each loop
$i = 0;
foreach ($_SESSION["cart_array"] as $each_item) {
$item_id = $each_item['item_id'];
$sql = mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1");
while ($row = mysql_fetch_array($sql)) {
$product_name = $row["product_name"];
$price = $row["price"];
$details = $row["details"];

}
//$pricetotal = $price * $each_item['quantity'];
//$cartTotal = $pricetotal + $cartTotal;
//setlocale(LC_MONETARY, "en_US");
//$pricetotal = money_format("%10.2n", $pricetotal);
// Dynamic Checkout Btn Assembly
$x = $i + 1;
//$pp_checkout_btn .= '<input type="hidden" name="item_name_' . $x . '" value="' . $product_name . '">
//<input type="hidden" name="amount_' . $x . '" value="' . $price . '">
//<input type="hidden" name="quantity_' . $x . '" value="' . $each_item['quantity'] . '"> ';
// Create the product array variable

$product_id_array .= "$item_id-".$each_item['quantity'].",";
$quantity = $each_item['quantity'];

//I did create the following two arrays to test///////////////////////////////
$mail_id_array .= "$product_name.--->.$quantity<br>";
array_push($sentoemail,$product_name,$each_item['quantity']);
//////////////////////////////////////////////////////////////////////////////

// Dynamic table row assembly
$cartOutput .= "<tr>";
$filename = "inventory_images/$item_id.jpg";
if (file_exists($filename)) {
$cartOutput .= '<td><a href="product.php?id=' . $item_id . '"></a><img src="inventory_images/' . $item_id . '.jpg" alt="' . $product_name. '" width="52" height="52" border="1" /></td>';
} else {
$cartOutput .= '<td><a href="product.php?id=' . $item_id . '"></a><img src="/pictures/products/Pcomingsoon.png" alt="' . $product_name. '" width="52" height="52" border="1" /></td>';
}
$cartOutput .= '<td><a href="product.php?id=' . $item_id . '">' . $product_name . '</a></td>';
$cartOutput .= '<td>$' . $price . '</td>';
$cartOutput .= '<td><form action="cart.php" method="post">
<input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" />
<input name="adjustBtn' . $item_id . '" type="submit" value="change" />
<input name="item_to_adjust" type="hidden" value="' . $item_id . '" />
</form></td>';
//$cartOutput .= '<td>' . $each_item['quantity'] . '</td>';
//$cartOutput .= '<td>' . $pricetotal . '</td>';
$cartOutput .= '<td><form action="cart.php" method="post"><input name="deleteBtn' . $item_id . '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' . $i . '" /></form></td>';
$cartOutput .= '</tr>';
$i++;
}
setlocale(LC_MONETARY, "en_US");
//$cartTotal = money_format("%10.2n", $cartTotal);
$cartTotal = "<div style='font-size:18px; margin-top:12px;' align='right'>Cart Total : ".$cartTotal." USD</div>";
// Finish the Paypal Checkout Btn
$pp_checkout_btn .= '<input type="hidden" name="custom" value="' . $product_id_array . '">
<input type="hidden" name="notify_url" value="https://www.yoursite.com/storescripts/my_ipn.php">
<input type="hidden" name="return" value="https://www.yoursite.com/checkout_complete.php">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="cbt" value="Return to The Store">
<input type="hidden" name="cancel_return" value="https://www.yoursite.com/paypal_cancel.php">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but01.gif" name="submit" alt="Make payments with PayPal - its fast, free and secure!">
</form>';
}
?>
<?
//this is the array i was playing with it does show a result but I do not know how to manipulate it to present it in a separate line on my email body
print_r($sentoemail);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/other.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>iiGLOO Frozen Desserts &amp; Supplies is Your Headquarters for Ice Cream &amp; Frozen Yogurt Supplies</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="iiGLOO,ice cream supplies,toppings,cones,containers,ingredients" />
<meta name="description" content="Do yourself a flavor and call iiGLOO Frozen Desserts & Extras, Inc. Ice cream supplies, in stock and ready to ship. Order by phone. Se habla español." />


<link href="css/master.css" rel="stylesheet" type="text/css" />
<!-- Start WOWSlider.com HEAD section -->
<link rel="stylesheet" type="text/css" href="engine1/style.css"/>
<link rel="stylesheet" type="text/css" href="engine1/style.css" />
<style type="text/css">
body {
background-image: url();
background-color: #A7C942;
}
</style>
<script type="text/javascript" src="engine1/jquery.js"></script>
<!-- End WOWSlider.com HEAD section -->

<!-- Vertical Accordion begins-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript" src="ddaccordion.js">


</script>


<script type="text/javascript">


ddaccordion.init({
headerclass: "submenuheader", //Shared CSS class name of headers group
contentclass: "submenu", //Shared CSS class name of contents group
revealtype: "click", //Reveal content when user clicks or onmouseover the header? Valid value: "click", "clickgo", or "mouseover"
mouseoverdelay: 200, //if revealtype="mouseover", set delay in milliseconds before header expands onMouseover
collapseprev: true, //Collapse previous content (so only one open at any time)? true/false
defaultexpanded: [], //index of content(s) open by default [index1, index2, etc] [] denotes no content
onemustopen: false, //Specify whether at least one header should be open always (so never all headers closed)
animatedefault: false, //Should contents open by default be animated into view?
persiststate: true, //persist state of opened contents within browser session?
toggleclass: ["", ""], //Two CSS classes to be applied to the header when it's collapsed and expanded, respectively ["class1", "class2"]
togglehtml: ["suffix", "<img src='plus.gif' class='statusicon' />", "<img src='minus.gif' class='statusicon' />"], //Additional HTML added to the header when it's collapsed and expanded, respectively ["position", "html1", "html2"] (see docs)
animatespeed: "fast", //speed of animation: integer in milliseconds (ie: 200), or keywords "fast", "normal", or "slow"
oninit:function(headers, expandedindices){ //custom code to run when headers have initalized
//do nothing
},
onopenclose:function(header, index, state, isuseractivated){ //custom code to run whenever a header is opened or closed
//do nothing
}
})


</script>
<!-- Vertical Accordion ends-->

<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->

<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="icon" href="/favicon.ico" type="image/x-icon">

</head>

<body>
<div class="header">
<!-- Website header area begins -->
<div class="topmargin">
</div>
<!-- Website logo and menu area area -->
<div id="div1">
<p class="cart"><a href="cart.php"><img src="pictures/view-cart-button.png" alt="" width="99" height="49" border=0 /></a></p>
<div id="MainMenu">
<ul>
<li><a href="index.php">Home</a></li>
</ul>
<ul>
<li><a href="#">Products</a>
<ul>
<li><a href="products.php">All Products</a></li>
<li><a href="vendors.php">All Vendors</a></li>
<li><a href="Price_List.php">Price List</a></li>
</ul>
</li>
</ul>
<ul>
<li><a href="customers.php">Customers</a></li>
</ul>
<ul>
<li><a href="documents/VALENTINESALES.pdf" target="_blank">Specials</a></li>
</ul>
<ul>
<li><a href="imember.php">iMembers</a></li>
</ul>
<ul>
<li><a href="contact.php">Contact Us</a></li>
</ul>
</div>
</div>
</div>
<!-- Website header area ends -->
<div class="centerarea"><!-- InstanceBeginEditable name="banners" -->
<div class="maincontent">
<!-- InstanceEndEditable --><!-- Banner Section Ends -->
<div class="inner">
<!-- Content Section Ends --><!-- Side Menu Ends --><!-- InstanceBeginEditable name="contentarea" -->
<div class="ocontent">
<div class="cartt">
<div style="margin:24px; text-align:left;">

<br />
<!-- Product Categorie Table Begins-->
<div class="itemstitle"><a id="basbas" name="basbas"></a>SHOPPING CART</div>
<div class="PTable">
<table align="center" id="products">
<tr>
<th width="11%">Product</th>
<th width="51%">Description</th>
<th width="7%">Price</th>
<th width="12%">Quantity</th>
<!-- th width="9%">Total</th>-->
<th width="10%">Remove</th>
</tr>
<?php echo $cartOutput; ?>
</table>
</div>
<!-- Product Categorie Table Ends-->
<?php echo $cartTotal; ?>
<br />
<br />
<?php echo $sentoemail; ?>
<?php //echo $pp_checkout_btn; ?>
<br />
<br />
<form id="form1" name="form1" method="post" action="/storescripts/mailcart.php">
<input type="hidden" name="message" id="message" value="<?php echo $mail_id_array; ?>" />
<input type="submit" name="button" id="button" value="Send Order" />
</form>
<br />
<br />
<a href="cart.php?cmd=emptycart">Click Here to Empty Your Shopping Cart</a>
</div>
</div>

</div>
<!-- InstanceEndEditable -->
<!-- Dynamic Area Ends -->

</div><!-- Content Section Ends -->

</div>
<div class="fcspace"></div>
<div class="fcontent">
<div class="fcontentinner">

<div class="fcontentmenu">
<p class="fcontentmenu">All content © 2012 IGFDS | terms and conditions<br/>
<a href="storeadmin/indexadmin.php">Admin</a> | careers | sitemap</p>
</div>
</div>
</div>
</body>
<!-- InstanceEnd --></html>


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//this is my cartemail.php page that is going to be use to send the results of the array to the email body
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
<?php
$message = '';
$name = "Willy Walker";
$email = "asd@hotttmail.com";
$message .= $_POST[message];
$formcontent=" From: $name \n Message: $message";
$recipient = "info@abc.com";
$subject = "Order Form";
$mailheader = "From: $email \r\n";
//mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
mail($recipient, $subject, $message, $mailheader) or die("Error!");
print_r($message);
//header( 'Location: http://www.abc.com/index.php' ) ;
//echo "Thank You!";

?>


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//this is what I would like to get at the email body
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Vanilla base flavor---->1
straberry base flavor--->7

I hope this is more explanatory than the previus email

thanks for your help


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest