PHP计算器表单不将结果发送到电子邮件地址

时间:2022-10-23 19:14:44

I have a calculator form and i want to send the results to my email address. It's posting the right data, but the response is just showing the full php code instead of "email sent"

我有一个计算器表单,我想将结果发送到我的电子邮件地址。它发布了正确的数据,但响应只是显示完整的PHP代码而不是“发送的电子邮件”

Here is a working example:

这是一个工作示例:

http://www.blackcatcoding.co.uk/calculator/calculator.php

and here is the php code behind it:

这是它背后的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>&pound;</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>&pound;</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>&pound;</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>&pound;</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>&pound;</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>&pound;</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>&pound;</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">&nbsp;</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>

1 个解决方案

#1


0  

I don't see anything defining "action" that you check in $_REQUEST['action'];

我没有看到你在$ _REQUEST ['action']中检查的定义“动作”的内容;

The <form action=""> won't do it. You may want to include an hidden input <input type="hidden" name="action" value="post" /> or change the way you're checking the data.

不会这样做。您可能希望包含隐藏的输入 或更改您检查数据的方式。

FYI you should also sticks to $_POST in your case (and use $_REQUEST only when needed)

在你的情况下你也应该坚持使用$ _POST(并且仅在需要时使用$ _REQUEST)

#1


0  

I don't see anything defining "action" that you check in $_REQUEST['action'];

我没有看到你在$ _REQUEST ['action']中检查的定义“动作”的内容;

The <form action=""> won't do it. You may want to include an hidden input <input type="hidden" name="action" value="post" /> or change the way you're checking the data.

不会这样做。您可能希望包含隐藏的输入 或更改您检查数据的方式。

FYI you should also sticks to $_POST in your case (and use $_REQUEST only when needed)

在你的情况下你也应该坚持使用$ _POST(并且仅在需要时使用$ _REQUEST)