我正在尝试通过电子邮件提交一个简单的表单,但是当我收到电子邮件时,$ _POST字段没有填充,邮件正文显示为:“名称:电子邮件:组织:角色:“没有数据。有什么想法吗?
HTML文件:
<form method="post" class="form-horizontal" id="contactForm" action="submit_contact.php"></div>
<div class="modal hide fade in" id="contactModal">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Submit form</h3>
</div>
<div class="modal-body">
<div style='display:none'></div>
<fieldset>
<div class="control-group">
<label class="control-label">Name</label>
<div class="controls">
<input id="name" type="text" name="name" maxlength="75" />
<p class="help-block" id="name_error"></p>
</div>
</div>
<div class="control-group">
<label class="control-label">E-mail</label>
<div class="controls">
<input id="email" type="text" name="email" maxlength="75" />
<p class="help-block" id="email_error"></p>
</div>
</div>
<div class="control-group">
<label class="control-label">Organization</label>
<div class="controls">
<input id="organization" type="text" name="organization" maxlength="75" />
<p class="help-block" id="organization_error"></p>
</div>
</div>
<div class="control-group">
<label class="control-label">Role</label>
<div class="controls">
<select name="occupation" id="id_occupation">
<option value="" selected="selected">---------</option>
<option value="MD">Medical Devices - Sales & Marketing</option>
<option value="MO">Medical Devices - Other</option>
<option value="MD">Physician</option>
<option value="OT">Other</option>
</select>
<p class="help-block" id="occupation_error"></p>
</div>
</div>
</fieldset>
</div>
<div class="modal-footer" style="height:30px">
<a name="submit" type="submit" value="submit" id="contactSubmit" class="btn btn-primary pull-right" href="#">
Submit
</a>
<p style="text-align: left; margin-top:6px;" id="contactFormStatus"></p>
</div>
</div>
</form>
</div>
<script>
$('#contactSubmit').on('click', function(e){
// We don't want this to act as a link so cancel the link action
e.preventDefault();
// Find form and submit it
$('#contactForm').submit();
});
</script>
submit_contact.php:
<?php
$ToEmail = 'xxx@xxx.com';
$EmailSubject = 'Site contact form';
$mailheader = "From: ".$_POST["name"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."";
$MESSAGE_BODY .= "\nEmail: ".$_POST["email"]."";
$MESSAGE_BODY .= "\nOrganization: ".$_POST["organization"]."";
$MESSAGE_BODY .= "\nRole: ".$_POST["occupation"]."";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
答案 0 :(得分:6)
<form method="request">
应该是
<form method="post">
答案 1 :(得分:0)
将HTML表单方法更改为发布而不是请求
form method =“request”...
到
form method =“post”...
答案 2 :(得分:0)
据我所知,“method”应为“post”,但您可以使用$ _REQUEST
访问它答案 3 :(得分:0)
<form method="post" class="form-horizontal" id="contactForm" action="submit_contact.php"> </div>
验证您的HTML,您有一个随机结束div
答案 4 :(得分:0)
将表单标签移动到模态体中最终解决了它。不要指望那是解决方案,但哦,好吧。