单击“提交”按钮时,联系表单不起作用

时间:2014-04-13 05:03:35

标签: php html form-submit contact-form submit-button

我正在使用HTML联系表单,其操作是发送php脚本的邮件。但是当我点击发送按钮时,它无法正常工作。我在这里找不到任何可能的东西。请有人帮我解决这个问题。

HTML表单

<div class="contact-form">
<form action="sendmail.php" method="post">
<div class="control-group"><label class="nameLabel" for="name">Name</label> <input id="name" name="name" type="text" /></div>

<div class="control-group"><label class="emailLabel" for="email">Email</label> <input id="email" name="email" type="text" /></div>

<div class="control-group"><label class="messageLabel" for="message">Message</label><textarea id="message" name="message"></textarea></div>

<div class="control-group"><button type="submit">Send</button></div>
</form>

<h1 class="status-message-contact"></h1>
</div>

PHP代码

<?php
 if(isset($_POST['submit']))
 {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $query = $_POST['message'];
    $email_from = $name.'<'.$email.'>';

 $to="sarath.sarigama@gmail.com";
 $subject="WEB Enquiry!";
 $headers  = 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 $headers .= "From: ".$email_from."\r\n";
 $message="   

         Name:
         $name     
         <br>
         Email-Id:
         $email        
         <br>
         Message:
         $query        

   ";
    if(mail($to,$subject,$message,$headers))
        header("Location:../index.php?msg=Successful Submission! Thankyou for contacting us.");
    else
        header("Location:../index.php?msg=Error To send Email !");
        //contact:-your-email@your-domain.com
 }
?>

4 个答案:

答案 0 :(得分:2)

您没有提交按钮名称,更改按钮的名称

<button name='submit' type="submit">Send</button>

或使用input代码

<input name='submit' type='submit'>

答案 1 :(得分:2)

You have change your button code with the following code


    <div class="contact-form">
    <form action="sendmail.php" method="post">
    <div class="control-group"><label class="nameLabel" for="name">Name</label> <input id="name" name="name" type="text" /></div>

    <div class="control-group"><label class="emailLabel" for="email">Email</label> <input id="email" name="email" type="text" /></div>

    <div class="control-group"><label class="messageLabel" for="message">Message</label><textarea id="message" name="message"></textarea></div>

    <div class="control-group"><input type="submit" name="send" value="send"></div>
    </form>

    <h1 class="status-message-contact"></h1>
    </div>

答案 2 :(得分:0)

替换

<button type="submit">Send</button>

<input type="submit" value="Send" />

也许可以添加

<input type="hidden" name="submit" value="1" />

对于isset($ _POST [&#39;提交&#39;])

答案 3 :(得分:0)

Please change the following snippet of code with your code
<html>
<head>
</head>
<body>
<div class="contact-form">
<form action="sendmail.php" method="post">
<div class="control-group"><label class="nameLabel" for="name">Name</label> <input id="name" name="name" type="text" /></div>
<div class="control-group"><label class="emailLabel" for="email">Email</label> <input id="email" name="email" type="text" /></div>
<div class="control-group"><label class="messageLabel" for="message">Message</label><textarea id="message" name="message"></textarea></div>
<div class="control-group"> <input type="submit" value="submit"></div>
</form>
<h1 class="status-message-contact"></h1>
</div>
</body>
</html>