I do not work in php, but I needed it.
For some reason, the name of objects is distorted, what is the problem and how to fix it ???
<?php header("Content-Type: text/html; charset=utf-8"); $servername = "**********"; $username = "********"; $password = "*******"; $dbname = "********"; function connect(){ $conn = mysqli_connect("*******", "********", "********", "********"); if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } return $conn; } function init(){ //вывожу список товаров $conn = connect(); $sql = "SELECT id, name FROM goods"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { $out = array(); while($row = mysqli_fetch_assoc($result)) { $out[$row["id"]] = $row; } echo json_encode($out); } else { echo "0"; } mysqli_close($conn); } ?> <?php header("Content-Type: text/html; charset=utf-8"); $mysqli->set_charset("utf8"); //читать json файл $json = file_get_contents( '../goods.json'); $json = json_decode($json, true); //письмо $message = ''; $message .= '<h1>Заказ в магазине</h1>'; $message .='<p>Телефон: '.$_POST['ephone'].'</p>'; $message .='<p>Почта: '.$_POST['email'].'</p>'; $message .='<p>Клиент: '.$_POST['ename'].'</p>'; $cart = $_POST['cart']; $sum = 0; foreach ($cart as $id=>$count) { $message .=$json[$id]['name'].' --- '; $message .=$count.' --- '; $message .=$count*$json[$id]['cost']; $message .='<br>'; $sum = $sum + $count*$json[$id]['cost']; } $message .='Всего: '.$sum; //print_r($message); $to = '******************'.','; $to .=$_POST['email']; $specttext = '<!DOCTYPE html><html><head><title>Заказ</title></head><body>'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n"; $m = mail($to, 'Заказ в магазине', $specttext.$message.'</body></html>', $headers); if ($m) {echo 1;} else {echo 0;} ?> 
