i have ionic app that send order details by email the email include the item name and size and Qty but when there is multi items in the cart it only sends the last item in the car details here is my controller code
.controller('checkoutCtrl', ['$scope', '$state', '$ionicPopup','$http','SERVER','sharedCartService',// The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $state, $ionicPopup, $http, SERVER, sharedCartService) {
$scope.cart=sharedCartService.cart;
$scope.total_qty=sharedCartService.total_qty;
$scope.total_amount=sharedCartService.total_amount;
$scope.data = {};
var itemNames ={};
$scope.submit = function(){
var link = 'http://www.myweb.net/catzOrderEmail.php';
for( var i = 0, len = $scope.cart.length; i < len; i++ ) {
itemNames = $scope.cart[i].cart_item_title;
alert(itemNames);
}
$http.post(link, {
Item_Name : itemNames ,//$scope.itemName,
Item_size : $scope.data.Size,
Item_qty : $scope.data.Qty,
total_qty : $scope.total_qty,
total_amount : $scope.total_amount,
FirstName : $scope.data.FirstName,
LastName : $scope.data.LastName,
Email : $scope.data.Email,
Country : $scope.data.Country,
City : $scope.data.City,
Street : $scope.data.Street,
Zip : $scope.data.Zip,
Phone : $scope.data.Phone
}).then(function (res){
this.myForm.reset();
$state.go('home');
});
};
}])
<?php
require "phpmailer/class.phpmailer.php"; //include phpmailer class
//require_once("geoiploc.php"); // Must include this
require_once("conf.php");
//http://stackoverflow.com/questions/15485354/angular-http-post-to-php-and-undefined
$postdata = file_get_contents("php://input");
if (isset($postdata)) {
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$request = json_decode($postdata);
$SubInput = "New Order";
$Item_Name = $request->Item_Name;
$Item_size = $request->Item_size;
$Item_qty = $request->Item_qty;
$total_qty = $request->total_qty;
$total_amount = $request->total_amount;
$FirstName = $request->FirstName;
$LastName = $request->LastName;
$Email = $request->Email;
$Country = $request->Country;
$City = $request->City;
$Street = $request->Street;
$Zip = $request->Zip;
$Phone = $request->Phone;
$to = "info@catzgear.net";
$hourdiff = "3";
$timeadjust = ($hourdiff * 3600);
$date = date("d-m-Y");
$MsTime = date("H:i:s",time() + $timeadjust);
//$userip = $_SERVER['REMOTE_ADDR'];
//$countryName = getCountryFromIP($userip, " NamE ");
$message = "<table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td align='center' valign='top' bgcolor='#ababab' style='background-color:#ababab;'><br>
<br>
<table width='600' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td align='left' valign='top'><img src='http://www.metalvoice.tv/images/maintop.png' width='600' height='17' style='display:block;'></td>
</tr>
<tr>
<td align='left' valign='top' bgcolor='#ffffff' style='background-color:#ffffff;'>
<table width='570' border='0' align='center' cellpadding='0' cellspacing='0' style='margin-bottom:15px;'>
<tr>
<td align='left' valign='middle' style='padding:10px;'></td>
</tr>
</table>
<table width='570' border='0' align='center' cellpadding='0' cellspacing='0' style='margin-bottom:15px;'>
<tr>
<td width='360' align='left' valign='middle' style='font-family:Arial, Helvetica, sans-serif; color:#4e4e4e; font-size:13px; padding-right:10px;'>
<div style='font-size:20px;'>
Date: $date<br><br>
Time: $MsTime<br><br>
Item Name: $Item_Name<br><br>
Item size: $Item_size<br><br>
Item Qty: $Item_qty<br><br>
total qty: $total_qty<br><br>
total Amount: $total_amount<br><br>
First Name: $FirstName<br><br>
Last Name: $LastName<br><br>
Email: $Email<br><br>
Country : $Country<br><br>
City: $City<br><br>
Street: $Street<br><br>
Zip: $Zip<br><br>
Phone: $Phone <br>
</div>
</td>
<td align='right' valign='middle'><table width='210' border='0' cellspacing='0' cellpadding='0'>
<tr>
</tr>
<tr>
</tr>
<tr>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
</tr>
</table>
<br>
<br></td>
</table> ";
// if ($Item_Name != "" ||
// $FirstName != "" ||
// $LastName != "" ||
// $Email != "" ||
// $Country != "" ||
// $City != "" ||
// $Street != "" ||
// $Zip != "" ||
// $Phone != ""
// ) {
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // Sets up a SMTP connection
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization
// $mail->SMTPSecure = "ssl"; // Connect using a TLS connection
$mail->Host = "mail.catzgear.net"; //Gmail SMTP server address
$mail->Port = 25; //Gmail SMTP port
$mail->Encoding = '7bit';
// Authentication
$mail->Username = "info@catzgear.net"; // Your full Gmail address
$mail->Password = $MyPass; // Your Gmail password
// Compose
$mail->SetFrom($Email, $FirstName);
$mail->Subject = $SubInput; // Subject (which isn't required)
$mail->MsgHTML($message);
// Send To
$mail->AddAddress($to, "Catz Gear"); // Where to send it - Recipient
$result = $mail->Send(); // Send!
$message = $result ? 'Successfully Sent!' : 'Sending Failed!';
unset($mail);
}
// else {
// echo "Sending Failed!";
// }
?>
how can i get all the items names in the cart
best regards