通过 Ajax 发送 js 多个数据到电子邮件
Sending js multiple data via Ajax to email
我需要通过 Ajax 将多个数据作为数组和表单输入值发送到电子邮件。这段代码有什么问题?该数组没有 return 发送电子邮件,猜测 php 文件中有问题
***html:
<form id="form-order">
First name:<br>
<input type="text" name="firstname">
<input type="tel" name="phonenumber">
<input type="submit" value="Submit">
</form>
***js:
$.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');
});
});
***PHP:
$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 段代码,您应该更好地截断这些片段,以便更好地支持编辑它并更轻松地阅读它,例如...。请注意,这只是一个方向,这不是有效的解决方案。
/* 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;
我需要通过 Ajax 将多个数据作为数组和表单输入值发送到电子邮件。这段代码有什么问题?该数组没有 return 发送电子邮件,猜测 php 文件中有问题 ***html:
<form id="form-order">
First name:<br>
<input type="text" name="firstname">
<input type="tel" name="phonenumber">
<input type="submit" value="Submit">
</form>
***js:
$.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');
});
});
***PHP:
$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 段代码,您应该更好地截断这些片段,以便更好地支持编辑它并更轻松地阅读它,例如...。请注意,这只是一个方向,这不是有效的解决方案。
/* 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;