联系表格(Php和html

时间:2016-11-13 19:00:00

标签: php html forms contact

所以我一直在使用联系表单,我创建了一些php和html表单但它将所有内容发送到我的电子邮件,除了用户放在表单中的电子邮件。一直在尝试下面的所有东西,没有任何作用

PHP:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$mail_to = 'email@email.com';
$subject = 'Message from a site visitor '.$name;

$body_message = 'From: '.$name."\n";
$body_message .= 'E-mail: '.$email."\n";
$body_message .= 'Message: '.$message;

$headers = 'From: '.$email."\r\n";
$headers .= 'Reply-To: '.$email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. We will contact you shortly.');
        window.location = 'contact_page.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to gordon@template-help.com');
        window.location = 'contact_page.html';
    </script>
<?php
}
?>

HTML:

            <form action="contact.php" method="post">
            <div class="row">
                <div class="col-md-4">
                <input type="text" class="form-control" id="name" placeholder="Name">
                <input type="text" class="form-control" id="email" placeholder="Email">
                <input type="text" class="form-control" id="subject" placeholder="Subject">
                </div>


                <div class="col-md-8">
                <textarea class="form-control" id="message" rows="25" cols="10" placeholder="  Message Texts..."></textarea>
                <button type="button" class="btn btn-default submit-btn form_submit">SEND MESSAGE</button>
                </div>
            </div>
            </form>

2 个答案:

答案 0 :(得分:0)

浏览完 script.js 文件后,我终于找到了问题所在。发送的变量email不是emaild。所以你的PHP修正将是:

$email = $_POST['emaild'];

答案 1 :(得分:-1)

尝试在表单的输入处添加名称字段。

请参阅以下代码

                    <form action="contact.php" method="post">
                    <div class="row">
                        <div class="col-md-4">
                            <input type="text" class="form-control" name="name" id="name" placeholder="Name">
                            <input type="text" class="form-control" name="email" id="email" placeholder="Email">
                            <input type="text" class="form-control" id="subject" placeholder="Subject">
                        </div>


                        <div class="col-md-8">
                            <textarea class="form-control" name="message" id="message" rows="25" cols="10" placeholder="  Message Texts..."></textarea>
                            <button type="button" class="btn btn-default submit-btn form_submit">SEND MESSAGE</button>
                        </div>
                    </div>
                </form>

有关更多信息,请参阅:http://www.w3schools.com/tags/att_input_name.asp