我在同一个php脚本中处理两个表单。提交第一个表单时,它会提示打开第二个表单,该表单在提交时将被发送到与第一个表单相同的php脚本。我曾尝试使用if(isset($_POST['details_submit']) && isset($_POST['customer_submit'])
同时处理这两个表单,但这两个表单都没有提交,但这并不起作用。我想同时处理来自两个表单的数据,因为第一个表单中的数据需要与第二个表单中的数据一起发送到邮件。这是我的代码:
<?php
if(isset($_POST['details_submit'])){
$body = json_decode(file_get_contents('php://input'),true);
$GLOBALS['details'] = "";
foreach ($body as $key => $value) {
$details.= "Item : ".$value['item_name'];
$details.= ", Quantity : ".$value['quantity'];
$details.= ", Amount : ".$value['amount'];
$details.= ", Total : ".$value['total']."\n";
}
echo $details;
$GLOBALS['subtotal'] = 0;
foreach ($body as $key => $value) {
$subtotal = $value['total'] + $subtotal;
}
echo $subtotal;
}// end if statement
if(isset($_POST['customer_submit'])){
$customer = "";
$customer.= "Customer : ".$_POST['Name']."\n";
$customer.= "Email : ".$_POST['Email']."\n";
$customer.= "Phone Number : ".$_POST['Phone']."\n";
$customer.= "Residence : ".$_POST['Area'];
echo $customer;
$email = $_POST['Email'];
$to = 'example@gmail.com';
$subject = 'Natures Touch Order';
$message = "<b>Customer Order</b> \n"
.$details."\n
<b>Customer Details</b> \n"
.$customer."\n
The subtotal is KSH ".$subtotal.".";
$headers = 'From: '.$email."\r\n";
'X-Mailer: PHP/' . phpversion();
$send1 = mail($to, $subject, $message, $headers);
}
?>
一切正常但是当我发送邮件时,我收到错误Undefined variables details and subtotal
,这可能是因为变量details
和subtotal
是以第一种形式处理的。关于如何处理这个问题的任何解决方案都将受到高度赞赏。