0

我正在尝试通过电子邮件提交一个简单的表单,但是当我收到电子邮件时,$_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"); 
?>
4

5 回答 5

6
<form method="request">

应该

<form method="post">
于 2013-02-11T21:48:27.743 回答
0

将您的 HTML 表单方法更改为发布而不是请求

形成方法=“请求”...

形成方法=“发布”...

于 2013-02-11T21:48:53.407 回答
0

据我所知,“方法”应该是“发布”,但您可以使用 $_REQUEST 访问它

于 2013-02-11T21:50:10.830 回答
0
<form method="post" class="form-horizontal" id="contactForm"     action="submit_contact.php"> </div> 

验证您的 HTML,您有一个随机关闭的 div

于 2013-02-11T22:18:26.667 回答
0

将表单标签移动到模态正文中最终解决了这个问题。没想到这是解决方案,但是哦。

于 2013-02-11T23:20:05.303 回答