我正在处理PHP的电子邮件,其中将重试5个表单字段并通过邮件发送。我得到了一些代码来实现这一点,其中代码只为4个文本字段编写,我有5个文本字段。问题是$ _POST没有检索第5个字段值,即使我按不同的顺序放置它也没有检索到该值。 以下是代码和结果。
letusknow.php文件:
<div class="row">
<form id="enquiryForm" class="form-horizontal" novalidate>
<fieldset>
<!-- Form Name -->
<legend>Free Quote</legend>
<!-- Text input-->
<div class="form-group">
<label class="col-md-2 control-label">Name</label>
<div class="col-md-4">
<input id="name" name="name" type="text" placeholder="Enter your name" class="form-control input-md" required data-validation-required-message="Please enter your Name.">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-2 control-label">Email</label>
<div class="col-md-4">
<input id="email" name="email" type="email" placeholder="Enter your email ID" class="form-control input-md" required data-validation-required-message="Please enter your Email Id.">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-2 control-label">Mobile</label>
<div class="col-md-4">
<input id="phone" name="phone" type="tel" placeholder="Enter your mobile number" class="form-control input-md" required data-validation-required-message="Please enter your Phone Number.">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-2 control-label">City</label>
<div class="col-md-4">
<input id="city" name="city" type="text" placeholder="Enter your city" class="form-control input-md" required data-validation-required-message="Please enter your City.">
</div>
</div>
<!-- Prepended text-->
<div class="form-group">
<label class="col-md-2 control-label">Product Loan Amount</label>
<div class="col-md-4">
<div class="input-group">
<span class="input-group-addon">(INR) ₹</span>
<input id="productLoan" name="productLoan" class="form-control" placeholder="Enter product loan amount" type="number" required data-validation-required-message="Please enter the Product Loan Amount.">
</div>
</div>
</div>
<!-- Multiple Checkboxes -->
<div class="form-group">
<label class="col-md-2 control-label" for="checkboxIAuthorize"></label>
<div class="col-md-4">
<div class="checkbox">
<label for="checkboxIAuthorize-0">
<input type="checkbox" id="checkboxIAuthorize-0" value="">
I authorize to contact me
</label>
</div>
</div>
</div>
<!-- For success/fail messages -->
<div id="success"></div>
<!-- Button -->
<div class="form-group">
<label class="col-md-2 control-label"></label>
<div class="col-md-4">
<button name="submit" type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
</div>
enquiry_mail.php文件:
<?php
$name = $_POST["name"];
$email_address = $_POST["email"];
$phone = $_POST["phone"];
$city = $_POST["city"];
$loan = $_POST["productLoan"];
// create email body and send it
$to = 'support@mysampledomain.com'; // PUT YOUR EMAIL ADDRESS HERE
$email_subject = "Enquiry Contact Form: $name"; // EDIT THE EMAIL SUBJECT LINE HERE
$email_body = "You have received a new enquiry from your website's Enquiry form.\n\n"."Here are the details:\nName: $name\nPhone: $phone\nEmail: $email_address\nCity: $city\nProduct Loan Amount: $loan";
$headers = "From: $email_address\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
我执行邮件后发送到support@mysampledomain.com,结果如下。
You have received a new enquiry from your website's Enquiry form.
Here are the details:
Name: TestName
Phone: 9191919191
Email: testname@testsample.com
City: Test City
Product Loan Amount:
此处产品贷款金额未按值重试。 $ _POST失败了。 帮我解决这个问题。
答案 0 :(得分:0)
将表单方法设置为POST
我试过
<input value="200" id="productLoan" name="productLoan" class="form-control" placeholder="Enter product loan amount" type="number" required data-validation-required-message="Please enter the Product Loan Amount.">
正在打印200的结果
但是当您在字段productLoan上键入字符串并尝试发布它时 它不会发布值,因为字段的类型是数字
希望你明白我的意思