我正在寻找一个解决方案,通过相同的HTML结果向我的产品确认页面(带有可用输入)发送电子邮件。我对从mail.php上的确认页面获取输入感到困惑。请在下面找到代码。感谢
stockdetailform.php
<html>
<head>
<title>Stockr Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h1>Stock Form</h1>
<form action="confirmation.php" method="post">
<p> Enter Total No. of iPad Air2:
<input type="text" name="ipadair2" size="30">
</p>
<p> Enter Total No. of iPhone6:
<input type="text" name="iphone6" size="30">
</p>
<p> Enter Total No. of iMac:
<input type="text" name="imac" size="30">
</p>
<p>
<button type="submit">Generate Report</button>
</p>
</form>
</body>
</html>
confirmation.php
<html>
<title>Confirm Order</title>
<head>
</head>
<body>
<div style="width:850px; margin-left:auto; margin-right:auto; margin-top:150px;">
<h2>Confirm Order</h2>
<?php
//Get the input.
$ipadair2 = $_POST['ipadair2'];
$iphone6 = $_POST['iphone6'];
$imac = $_POST['imac'];
//Compute totals.
$stock_total = $ipadair2 + $iphone6 + $imac ;
//Output totals.
if(isset($_POST['ipadair2']) && is_numeric($_POST['ipadair2'])){
$ipadair2 = $_POST['ipadair2'];
} else {
$ipadair2 = 0;
}
if(isset($_POST['iphone6']) && is_numeric($_POST['iphone6'])){
$iphone6 = $_POST['iphone6'];
} else {
$iphone6 = 0;
}
if(isset($_POST['imac']) && is_numeric($_POST['imac'])){
$imac= $_POST['imac'];
} else {
$imac= 0;
}
?>
<table width="850" border="0" cellpadding="5" cellspacing="0" style="border:1px solid #ccc;">
<tr bgcolor="#f7f7f7" >
<th width="696" height="37" align="left" style="border-bottom:1px solid #ccc;">Product</th>
<th width="128" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;">Quantity</th>
</tr>
<?php
if($ipadair2 > 0){
?>
<tr>
<td height="32" style="border-bottom:1px solid #ccc;">ipadair2</td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;"><?php print $ipadair2; ?></td>
</tr>
<?php
}
?>
<?php
if($iphone60 > 0){
?>
<tr>
<td height="32" style="border-bottom:1px solid #ccc;">iphone6</td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;"><?php print $iphone6; ?></td>
</tr>
<?php
}
?>
<?php
if($imac > 0){
?>
<tr>
<td height="32" style="border-bottom:1px solid #ccc;">imac</td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;"><?php print $imac; ?></td>
</tr>
<?php
}
?>
<tr>
<td height="55" ><strong>Total Items</strong></td>
<td align="center" width="128"><?php print $quote_total; ?></td>
</tr>
<tr>
<td colspan="2"><form method="post" action="mail.php">
<input type='hidden' name='ipadair2' value='<?php if(isset($ipadair2) && $ipadair2 >0){echo $ipadair2;}else{echo "0";} ?>'>
<input type='hidden' name='iphone6' value='<?php if(isset($iphone6) && $iphone6 >0){echo $iphone6;}else{echo "0";} ?>'>
0){echo $ imac;} else {echo“0”;}?&gt;'&gt;
/ TD&GT;
mail.php
<?php
/* Subject and email variables */
$emailsSubject = 'STOCK STATUS';
$webMaster = 'maxcomtesting@gmail.com';
//Get the input.
$ipadair2 = $_POST['ipadair2'];
$iphone6 = $_POST['iphone6'];
$imac = $_POST['imac'];
//Compute totals.
$stock_total = $ipadair2 + $iphone6 + $imac ;
//Output totals.
if(isset($_POST['ipadair2']) && is_numeric($_POST['ipadair2'])){
$ipadair2 = $_POST['ipadair2'];
} else {
$ipadair2 = 0;
}
if(isset($_POST['iphone6']) && is_numeric($_POST['iphone6'])){
$iphone6 = $_POST['iphone6'];
} else {
$iphone6 = 0;
}
if(isset($_POST['imac']) && is_numeric($_POST['imac'])){
$imac= $_POST['imac'];
} else {
$imac= 0;
}
?>
$body = <<<EOD
<table width="850" border="0" cellpadding="5" cellspacing="0" style="border:1px solid #ccc;">
<tr bgcolor="#f7f7f7" >
<th width="696" height="37" align="left" style="border-bottom:1px solid #ccc;">Product</th>
<th width="128" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;">Quantity</th>
</tr>
<?php
if($ipadair2 > 0){
?>
<tr>
<td height="32" style="border-bottom:1px solid #ccc;">ipadair2</td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;"><?php print $ipadair2; ?></td>
</tr>
<?php
}
?>
<?php
if($iphone60 > 0){
?>
<tr>
<td height="32" style="border-bottom:1px solid #ccc;">iphone6</td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;"><?php print $iphone6; ?></td>
</tr>
<?php
}
?>
<?php
if($imac > 0){
?>
<tr>
<td height="32" style="border-bottom:1px solid #ccc;">imac</td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;"><?php print $imac; ?></td>
</tr>
<?php
}
?>
<tr>
<td height="55" ><strong>Total Items</strong></td>
<td align="center" width="128"><?php print $quote_total; ?></td>
</tr>
<tr>
<td colspan="2"><form method="post" action="mail.php">
<input type='hidden' name='ipadair2' value='<?php if(isset($ipadair2) && $ipadair2 >0){echo $ipadair2;}else{echo "0";} ?>'>
<input type='hidden' name='iphone6' value='<?php if(isset($iphone6) && $iphone6 >0){echo $iphone6;}else{echo "0";} ?>'>
<input type='hidden' name='imac' value='<?php if(isset($imac) && $imac >0){echo $imac;}else{echo "0";} ?>'>
<input type="submit" value="SEND MAIL" name='submit' >/td>
</tr>
</table>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
/* This is what sends the email */
$success = mail($webMaster, $emailsSubject, $body, $headers);
/* Results Rendered as Html */
echo file_get_contents("http://yourdomain.com/after-message-sent/");
?>
以下结果(电子邮件)现已开始
mail.php,无需任何计算
<?php
//Get the input.
$ipadair2 = $_POST['ipadair2'];
$iphone6 = $_POST['iphone6'];
$imac = $_POST['imac'];
/* Subject and email variables */
$emailsSubject = 'STOCK STATUS';
$webMaster = 'sample@gmail.com';
/* What You Want To See In The Email Place Inbetween $body = <<<EOD and EOD; */
$body = <<<EOD
<table width="850" border="0" cellpadding="5" cellspacing="0" style="border:1px solid #ccc;">
<tr bgcolor="#CCCCCC" >
<th width="696" height="37" align="left" style="border-bottom:1px solid #ccc; font-size:18px;">Product</th>
<th width="128" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc; font-size:18px;">Quantity</th>
</tr>
<tr bgcolor="#F9F9F9" >
<td height="32" style="border-bottom:1px solid #ccc;"><strong>iPadair2</strong></td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc; color:#15c; font-weight:bold;">$ipadair2</td>
</tr>
<tr >
<td height="32" style="border-bottom:1px solid #ccc;"><strong>iPhone6</strong></td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc; color:#15c;font-weight:bold;">$iphone6</td>
</tr>
<tr bgcolor="#F9F9F9">
<td height="32" style="border-bottom:1px solid #ccc;"><strong>iMac</strong></td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc; color:#15c;font-weight:bold;">$imac</td>
</tr>
</table>
<br />
<br />
EOD;
/* Headers is a tag containing the users email and how you want it to display in your email */
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
/* This is what sends the email */
$success = mail($webMaster, $emailsSubject, $body, $headers);
/* Results Rendered as Html */
echo file_get_contents("http://yourdomain.com/after-message-sent/");
?>
答案 0 :(得分:1)
纠正了一些错误,即stock_total没有设置等,现在应该工作
Stackdetail.php
<html>
<head>
<title>Stockr Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<h1>Stock Form</h1>
<form action="confirmation.php" method="post">
<label for ="email">Enter your Email
<input type="email" name="email" />
</label>
<p> Enter Total No. of iPad Air2:
<input type="text" name="ipadair2" size="30">
</p>
<p> Enter Total No. of iPhone6:
<input type="text" name="iphone6" size="30">
</p>
<p> Enter Total No. of iMac:
<input type="text" name="imac" size="30">
</p>
<p>
<button type="submit">Generate Report</button>
</p>
</form>
</body>
</html>
Confirmation
<html>
<title>Confirm Order</title>
<head>
</head>
<body>
<div style="width:850px; margin-left:auto; margin-right:auto; margin-top:150px;">
<h2>Confirm Order</h2>
<?php
//Get the input.
$ipadair2 = $_POST['ipadair2'];
$iphone6 = $_POST['iphone6'];
$imac = $_POST['imac'];
$email= $_POST['email'];
//Compute totals.
$stock_total = $ipadair2 + $iphone6 + $imac ;
//Output totals.
if(isset($_POST['ipadair2']) && is_numeric($_POST['ipadair2'])){
$ipadair2 = $_POST['ipadair2'];
} else {
$ipadair2 = 0;
}
if(isset($_POST['iphone6']) && is_numeric($_POST['iphone6'])){
$iphone6 = $_POST['iphone6'];
} else {
$iphone6 = 0;
}
if(isset($_POST['imac']) && is_numeric($_POST['imac'])){
$imac= $_POST['imac'];
} else {
$imac= 0;
}
?>
<table width="850" border="0" cellpadding="5" cellspacing="0" style="border:1px solid #ccc;">
<tr bgcolor="#f7f7f7" >
<th width="696" height="37" align="left" style="border-bottom:1px solid #ccc;">Product</th>
<th width="128" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;">Quantity</th>
</tr>
<?php
if($ipadair2 > 0){
?>
<tr>
<td height="32" style="border-bottom:1px solid #ccc;">ipadair2</td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;"><?php print $ipadair2; ?></td>
</tr>
<?php
}
?>
<?php
if($iphone6 > 0){
?>
<tr>
<td height="32" style="border-bottom:1px solid #ccc;">iphone6</td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;"><?php print $iphone6; ?></td>
</tr>
<?php
}
?>
<?php
if($imac > 0){
?>
<tr>
<td height="32" style="border-bottom:1px solid #ccc;">imac</td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;"><?php print $imac; ?></td>
</tr>
<?php
}
?>
<tr>
<td height="55" ><strong>Total Items</strong></td>
<td align="center" width="128"><?php print $stock_total; ?></td>
</tr>
<tr>
<td colspan="2"><form method="post" action="mail.php">
Your Confirmation email will be sent to : <?php echo " $email "; ?>
<input type='hidden' name="email" value='<?php if(isset($email)){echo $email;}?>'>
<input type='hidden' name='imac' value='<?php if(isset($imac) && $imac >0){echo $imac;}else{echo "0";} ?>'>
<input type='hidden' name='ipadair2' value='<?php if(isset($ipadair2) && $ipadair2 >0){echo $ipadair2;}else{echo "0";} ?>'>
<input type='hidden' name='iphone6' value='<?php if(isset($iphone6) && $iphone6 >0){echo $iphone6;}else{echo "0";} ?>'>
<input type="submit" value="Confirm Order" />
mail.php
<?php
/* Subject and email variables */
$emailsSubject = 'STOCK STATUS';
$webMaster = 'maxcomtesting@gmail.com';
$email= $_POST['email']; //Get the input.
$ipadair2 = $_POST['ipadair2'];
$iphone6 = $_POST['iphone6'];
$imac = $_POST['imac'];
//Compute totals.
$stock_total = $ipadair2 + $iphone6 + $imac ;
//Output totals.
if(isset($_POST['ipadair2']) && is_numeric($_POST['ipadair2'])){
$ipadair2 = $_POST['ipadair2'];
} else {
$ipadair2 = 0;
}
if(isset($_POST['iphone6']) && is_numeric($_POST['iphone6'])){
$iphone6 = $_POST['iphone6'];
} else {
$iphone6 = 0;
}
if(isset($_POST['imac']) && is_numeric($_POST['imac'])){
$imac= $_POST['imac'];
} else {
$imac= 0;
}
$body = '
<table width="850" border="0" cellpadding="5" cellspacing="0" style="border:1px solid #ccc;">
<tr bgcolor="#f7f7f7" >
<th width="696" height="37" align="left" style="border-bottom:1px solid #ccc;">Product</th>
<th width="128" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;">Quantity</th>
</tr>';
if($ipadair2 > 0){
$body.='
<tr>
<td height="32" style="border-bottom:1px solid #ccc;">ipadair2</td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;">'.$ipadair2.'</td>
</tr>';
}
if($iphone6 > 0){
$body.=
'<tr>
<td height="32" style="border-bottom:1px solid #ccc;">iphone6</td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;">'. $iphone6.'</td>
</tr>';
}
if($imac > 0){
$body.='
<tr>
<td height="32" style="border-bottom:1px solid #ccc;">imac</td>
<td align="center" style="border-bottom:1px solid #ccc; border-left:1px solid #ccc;">'. $imac.'</td>
</tr>';
}
$body .='
<tr>
<td height="55" ><strong>Total Items</strong></td>
<td align="center" width="128">'.$stock_total.'</td>
</tr>
<tr>
<td colspan="2"><form method="post" action="mail.php">';
$body .=" <input type='hidden' name='email' value='$email'>
<input type='hidden' name='ipadair2' value='$ipadair2'>
<input type='hidden' name='iphone6' value='$iphone6'>
<input type='hidden' name='imac' value='$imac'>
<input type='submit' value='SEND MAIL' name='submit' ></td>
</tr>
</table>";
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
/* This is what sends the email */
$success = mail($webMaster, $emailsSubject, $body, $headers);
/* Results Rendered as Html */
//echo file_get_contents("http://yourdomain.com/after-message-sent/");
header('location:http://google.com');exit;
?>
&#13;