PHP联系表单未提交 [英] PHP Contact Form not submitting

查看:100
本文介绍了PHP联系表单未提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我以前使用过这个非常简单的php联系脚本但是当我尝试在新的HTML页面上实现它时,表单将无法提交。谁能看到任何明显的错误?
我们非常感谢任何帮助

Hi I've previously used this very simple php contact script with success though when I've tried implementing it on a new HTML page with the form won't submit. Can anyone see any obvious errors? Any help would be much appreciated

以下是表单的html:

Here is the html of the form:

<div id="formContainer">

    <form action="form.php" method="post" id="contactForm"> 
    <fieldset>

    <legend>Your details</legend>    

    <label for="name">Name *</label>
    <input type="text" id="name">

    <label for="email">Email *</label>
    <input type="email" id="email">

    <label for="tel">Telephone</label>
    <input type="tel" id="tel">

    </fieldset>

    <fieldset> 
    <legend>Tutoring</legend>

    <label for="type">Type of lesson</label>
    <select name="type" id="type">
    <option>Individual</option>
    <option>Group</option>
    </select>

    <label for="subject">Subject</label>
    <input name="subject" list="subjects" id="subject">
    <datalist id="subjects">
    <option>English</option>
    <option>Biology</option>
    <option>Geography</option>
    </datalist>

    <label for="level">Your level</label>
    <select name="level" id="level">
    <option>Beginner</option>
    <option>GCSE</option>
    <option>A-Level</option>
    <option>University</option>
    </select>

    <label for="hours">Hours/week</label>
    <input type="number" id="hours">

    <label for="info">Additional Information</label>
    <textarea name="info" id="info" rows="10"               cols="6"></textarea>


    </fieldset>

    <input type="submit" name="submit" value="Send" id="sendButton">

    <input type="hidden" name="submit_check" value="1" />   
    </form>

    </div>

这是简单的PHP脚本:

And here is the simple php script:

<?php 

if ($_POST["email"]<>'') { 
    $ToEmail = 'onjegolders@gmail.com'; 
    $EmailSubject = 'Site contact form '; 
    $mailheader = "From: ".$_POST["email"]."\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"]."<br>"; 
    $MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>"; 
    $MESSAGE_BODY = "Telephone: ".$_POST["tel"]."<br>";
    $MESSAGE_BODY = "Type: ".$_POST["type"]."<br>";
    $MESSAGE_BODY = "Subject: ".$_POST["subject"]."<br>";
    $MESSAGE_BODY = "Level: ".$_POST["level"]."<br>";
    $MESSAGE_BODY = "Hours required: ".$_POST["hours"]."<br>";
    $MESSAGE_BODY .= "Additional information: ".nl2br($_POST["info"])."<br>"; 
    mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); 

?> 

<html>

    <h3>Thanks for your email</h3>
    <h4>I'll get back to you as soon as possible</h4>
    <a href="index.html"><p>Click here to go back to previous page</p></a>

</html>


<?php 
} else { 
?> 

<html>Sorry, this form didn't work</html>

<?php 
}; 
?>


推荐答案

尝试

if ( !empty($_POST["email"]) )

但是你可以检查,该页面上发布的是什么:

However you can check, what is posted in that page using:

echo '<pre>';
var_dump( $_POST );

这篇关于PHP联系表单未提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆