0

我只是想在我的网站上设置一个新的电子邮件表单,我已经设法让它从表单中获取电子邮件、评论和名称,并在用户按下提交时将它们发送到我指定的电子邮件地址 - 我的问题我如何添加额外的字段让我们说车辆登记和电话号码?

我假设我会使用相同的属性但使用不同的 id 向表单添加另外 2 个字段,然后编辑 send-mail.php 文件并将这两个新变量添加到 send-mail.php 文件中已有的变量旁边,即电子邮件变量和名称变量和评论变量。

这是我想出的代码,因为它现在仍然有效,但我没有收到发送到我的电子邮件的所有信息,它缺少 2 个新变量....

  <!-- form -->
                <script type="text/javascript" src="js/form-validation.js"></script>
                <form id="contactForm" action="#" method="post">
                    <h2 class="heading">Contact us using this form</h2>
                    <p>If you have any queries at all or just want to get rid of your car as soon as possible then just leave us the requested details on the form below, press send and a member of our team will get back to you soon.</p>
                    <fieldset>
                        <div>
                            <input name="name"  id="name" type="text" class="form-poshytip" title="Enter your full name" />
                            <label>Name</label>
                        </div>
                        <div>
                            <input name="email"  id="email" type="text" class="form-poshytip" title="Enter your email address" />
                            <label>Email</label>
                        </div>
                        <div>

                            <input name="reg"  id="reg" type="text" class="form-poshytip" title="Enter your vehicle registration" />
                            <label>Vehicle Registration</label>
                        </div>
                        <div>

                            <input name="phone"  id="phone" type="text" class="form-poshytip" title="Enter your phone number" />
                            <label>Phone Number</label>
                        </div>
                        <div>
                            <textarea  name="comments"  id="comments" rows="5" cols="20" class="form-poshytip" title="Enter your comments"></textarea>
                        </div>

                        <!-- send mail configuration -->
                        <input type="hidden" value="enquiries@scrapyourmotor.com" name="to" id="to" />
                        <input type="hidden" value="ScrapYourMotor FORM" name="subject" id="subject" />
                        <input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" />
                        <!-- ENDS send mail configuration -->

                        <p><input type="button" value="Send" name="submit" id="submit" /> <span id="error" class="warning">Message</span></p>
                    </fieldset>

                </form>
                <p id="sent-form-msg" class="success">Form data sent. Thanks for your comments.</p>
                <!-- ENDS form -->

和 php 文件....

                <?php
                //vars
                $subject = $_POST['subject'];
                $to = explode(',', $_POST['to'] );

                $from = $_POST['email'];

                //data
                $msg = "NAME: "  .$_POST['name']    ."<br>\n";
                $msg .= "EMAIL: "  .$_POST['email']    ."<br>\n";
                $msg .= "REG: "  .$_POST['reg']    ."<br>\n";
                $msg .= "PHONE: "  .$_POST['phone']    ."<br>\n";
                $msg .= "COMMENTS: "  .$_POST['comments']    ."<br>\n";

                //Headers
                $headers  = "MIME-Version: 1.0\r\n";
                $headers .= "Content-type: text/html; charset=UTF-8\r\n";
                $headers .= "From: <".$from. ">" ;


                //send for each mail
                foreach($to as $mail){
                   mail($mail, $subject, $msg, $headers);
                }

                ?>

我哪里错了?这是我在电子邮件中得到的输出:

NAME:我发送的名字

EMAIL:我发送的电子邮件

车辆登记:(这里什么都没有?)

电话号码:(这里什么都没有?)

评论:我发送的评论

感谢任何帮助的人:)

4

1 回答 1

0

啊,我真傻,我忘了用 2 个新变量更新 form-validation.js 文件:) ...

        // reg
    var reg = $("input#reg").val();
    if(reg == ""){
        $("#error").fadeIn().text("Reg required");
        $("input#reg").focus();
        return false;
    }

    // comments
    var comments = $("#comments").val();

    // phone
    var phone = $("#phone").val();
于 2013-04-22T00:06:53.097 回答