1

我使用 requires 属性创建了一个联系表单。现在我想在不刷新页面的情况下提交此电子邮件表单。当我用谷歌搜索它时,我得到了验证码,我不需要验证,因为我在我的 html 中使用了 required 属性。我只想要那个我可以添加的功能,这样页面在提交后不会被刷新,并且电子邮件应该去..

索引.html

<!DOCTYPE html>
<html>  
    <head>
        <meta charset="utf-8">
        <title>HTML5 Contact Form</title>
        <link rel="stylesheet" media="screen" href="styles.css">
    </head>     
    <body>
        <div id="contact">
            <form class="contact_form" action="contact.php" method="post" name="contact_form">
                <ul>
                    <li>
                         <h2>Contact Us</h2>
                         <span class="required_notification">* Denotes Required Field</span>

                    </li>
                    <li>
                        <label for="name">Name:</label>
                        <input type="text" id="name" name="name" placeholder="John Doe" required />
                    </li>
                    <li>
                        <label for="email">Email:</label>
                        <input type="email" name="email" id="email" placeholder="john_doe@example.com" required /> <span class="form_hint">Proper format "name@something.com"</span>

                    </li>
                    <li>
                        <label for="message">Message:</label>
                        <textarea name="message" id="message" cols="40" rows="6" required></textarea>
                    </li>
                    <li>
                        <button class="submit" id="submit_btn" type="submit">Submit Form</button>
                    </li>
                </ul>
            </form>
        </div>
    </body>
</html>

联系人.php

<?php
    $field_name = $_POST['name'];
    $field_email = $_POST['email'];
    $field_message = $_POST['message'];
    $mail_to = 'babloopuneeth@gmail.com';
    $subject = 'Message from a site visitor '.$field_name;
    $body_message = 'From: '.$field_name."\n";
    $body_message .= 'E-mail: '.$field_email."\n";
    $body_message .= 'Message: '.$field_message;
    $headers = 'From: '.$field_email."\r\n";
    $headers .= 'Reply-To: '.$field_email."\r\n";
    $mail_status = mail($mail_to, $subject, $body_message, $headers);

    if ($mail_status) {
        ?>

        </script>
    <?php
     } else { ?>

    <?php
     } 
?>

我不知道在 if 和 else 案例中添加什么来实现我的目标?请帮帮我。。

4

2 回答 2

0

您必须使用jQuery'ajax函数发送表单而不刷新页面,这是官方文档:http ://api.jquery.com/jQuery.ajax/

希望能帮助到你!

于 2013-07-21T18:00:13.007 回答
0

只需将其用作contact.php

<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_message = $_POST['message'];
$mail_to = 'babloopuneeth@gmail.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
?>
于 2013-07-21T18:51:52.213 回答