我有一个计算器表单,我想将结果发送到我的电子邮件地址。它发布了正确的数据,但响应只是显示完整的PHP代码而不是“发送电子邮件”
这是一个有效的例子:
http://www.blackcatcoding.co.uk/calculator/calculator.php
这里是它背后的php代码:
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
function propType(id)
{
var pprice = document.getElementById('pur_price').value;
var rate1 = document.getElementById('select2').value;
var refurb = document.getElementById('refurb').value;;
document.getElementById('avg_claim_rate').value=id;
var result1 = +pprice + + refurb;
var result2 = result1 * rate1;
document.getElementById('amount_claim').value=result2;
}
function calculate()
{
var tax_rate=document.getElementById('tax_rate').value;
var amount_claim=document.getElementById('amount_claim').value;
var client_benefit=amount_claim*tax_rate;
var cash_reclaim=client_benefit*0.36;
var future_tax_rel=client_benefit-cash_reclaim;
//$('#future_tax_rel').text(future_tax_rel);
document.getElementById('future_tax_rel').value=future_tax_rel;
document.getElementById('client_benefit').value=client_benefit;
document.getElementById('cash_reclaim').value=cash_reclaim;
return false;
}
</script>
<div class="main_box">
<div class="clear"></div>
<div class="clear"></div>
<?php
$action=$_REQUEST['action'];
if ($action=="") /* display the contact form */
{
?>
<form action="" method="POST" enctype="multipart/form-data">
<div class="main_col">
<div class="main_col_left"><strong>BUSINESS NAME:</strong></div>
<div class="main_col_right">
<input type="text" name="business" id="business" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>EMAIL ADDRESS:</strong></div>
<div class="main_col_right">
<input type="text" name="email" id="email" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>PROPERTY PURCHASE PRICE:</strong><span><strong>£</strong></span></div>
<div class="main_col_right">
<input type="text" name="pur_price" id="pur_price" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>REFURB COST:</strong><span><strong>£</strong></span></div>
<div class="main_col_right">
<input type="text" name="refurb" id="refurb" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>Property Type :</strong></div>
<div class="main_col_right">
<select name="select2" id="select2" onChange="propType(this.value);">
<option value="">Select Property Type</option>
<option value="0.3">Car Showroom</option>
<option value="0.4">Care/Nursing Home</option>
<option value="0.25">Dental Surgery</option>
<option value="0.3">Department Store</option>
<option value="0.3">Distribution Centre</option>
<option value="0.3">FHL Apartment</option>
<option value="0.3">FHL House</option>
<option value="0.3">FHL Villa</option>
</select>
</div>
</div>
<div class="main_col" style="display:none">
<div class="main_col_left"><strong>AVERAGE CLAIM RATE :</strong><span><strong>£</strong></span></div>
<div class="main_col_right">
<input type="text" name="avg_claim_rate" id="avg_claim_rate" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>AMOUNT CLAIMABLE :</strong><span><strong>£</strong></span></div>
<div class="main_col_right">
<input type="text" name="amount_claim" id="amount_claim" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong> YOUR TAX RATE :</strong></div>
<div class="main_col_right">
<select name="tax_rate" id="tax_rate">
<option value=".24">24%</option>
<option value=".4">40%</option>
</select>
</div>
</div>
<div class="clear"></div>
<hr />
<div class="clear"></div>
<div class="main_col">
<div class="main_col_left"><strong>CLIENT TAX BENEFIT :</strong><span><strong>£</strong></span></div>
<div class="main_col_right">
<input type="text" name="client_benefit" id="client_benefit" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>INSTANT CASH RECLAIM:</strong><span><strong>£</strong></span></div>
<div class="main_col_right">
<input type="text" name="cash_reclaim" id="cash_reclaim" value="" />
</div>
</div>
<div class="main_col">
<div class="main_col_left"><strong>FUTURE TAX RELIEF :</strong><span><strong>£</strong></span></div>
<div class="main_col_right"><!--<span id="future_tax_rel"></span>-->
<input type="text" name="future_tax_rel" id="future_tax_rel" value="" />
</div>
</div>
<div class="clear"></div>
<hr />
<div class="clear"></div>
<p style="line-height:20px;">Note : These figures are estimates and the final figures may very depending upon the property and full circusstances</p>
<div class="clear"></div>
<div class="clear"></div>
<div class="main_col">
<div class="main_col_left"> </div>
<div class="main_col_right">
<button onClick="calculate();">Calculate</button>
</div>
</div>
</form>
<?php
}
else /* send the submitted data */
{
$name=$_REQUEST['business'];
$email=$_REQUEST['email'];
$pur_price=$_REQUEST['pur_price'];
$refurb=$_REQUEST['refurb'];
$select2=$_REQUEST['select2'];
$select=$_REQUEST['select'];
if (($name=="")||($email==""))
{
echo "Please enter business name & email";
}
else{
$from="From: $name<$email>\r\nReturn-path: $email";
$subject="Message sent using your contact form";
mail("carladessi@hotmail.com", $subject, $from);
echo "Email sent!";
}
}
?>
<div class="clear"></div>
<div class="clear"></div>
</div>
答案 0 :(得分:0)
我没有看到任何定义&#34;动作&#34;您签入$ _REQUEST [&#39; action&#39;];
&lt; form action =&#34;&#34;&gt;不会做的。您可能希望包含隐藏的输入&lt; input type =&#34; hidden&#34;命名=&#34;动作&#34;值=&#34;后&#34; /&GT;或者改变你检查数据的方式。
仅供参考,你也应该坚持使用$ _POST(仅在需要时使用$ _REQUEST)