我需要将多个数据作为数组发送,并通过Ajax将输入值形成电子邮件。这段代码有什么问题?数组没有返回电子邮件,猜测php文件中的错误 *** HTML:
$.ajax({
type: "POST",
data: {mydata: JSON.stringify(MyObjects)},
url: "index.php",
success: function(data){
}
});
var array = [{count:1,image:"images/1.jpg",name:"Bouquet 1",price:49},{count:5,image:"images/1.jpg",name:"Bouquet 9",price:77}];
$("#form-order").submit(function() {
var order_data = cart;
$.ajax({
type: "POST",
url: "../order.php",
data: {form: form_data,
order:JSON.stringify(order_data)},
success: function() {
console.log('OK');
});
});
*** JS:
$to = "mail@mail.ru";
$message = '
<html>
<head>
</head>
<body>
<p>Name: '.$_POST['first name'].'</p>
<p>Phone: '.$_POST['phone number'].'</p>
$someArray;
$extradata = json_decode($_POST['order'], true);
foreach ($extradata as $key => $value) {
$someArray .= "<p>".$value["image"] . ", " .
$value["name"] . "</p>";
</body>
</html>';
*** PHP:
x = "123"
s=0
for a in x:
s= int(a)+s
答案 0 :(得分:0)
对于你的PHP代码,你应该更好地截断这些部分,以便更好地支持编辑它并更容易阅读....请注意,这只是一个方向,它不是工作的解决方案。
/* Defintions */
$to = "mail@mail.ru";
$extradata = json_decode($_POST['order'],true);
/* HTML Structure */
$head = "
<html>
<head>
</head>
<body>
";
$footer = "
</body>
</html>';
";
/* Content */
$content = "";
$content .= "<p>Name:".$_POST['first name']."</p>";
$content .= "<p>Name:".$_POST['phone number']."</p>";
foreach($extradata as $key => $value)
{
$content .= "<p>".$key."=".$value['image']."</p>";
}
$htmlEmail = $head.$content.$footer;