0

所以我的网站需要在今晚更新,我是 PHP 菜鸟。我正在尝试通过电子邮件提交一个简单的表格。但是,当我收到电子邮件时,$_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

0 回答 0