简体   繁体   English

我创建的网络表单存在问题

[英]I have an issue with a web form I have created

The problem I have is that the form I have created I am sure I am missing something simple for some reason it does not send the phone number to the email all of the other fields get sent and are outputted in the emai. 我的问题是我创建的表单由于某些原因我肯定丢失了一些简单的东西,因为它没有将电话号码发送到电子邮件中,其他所有字段都已发送并在emai中输出。

The HTML form is below: HTML表单如下:

            <div class="form-wrapper">
                <p id="success"></p>
                    <form id="contact-form" name="contact-form" method="POST">
                    <label class="label">Name:</label>
                    <p><input type="text" value="" name="contact-names" class="contact-names"/><span class="name-required"></span></p>
                    <label class="label">Email:</label>
                     <p><input type="text" value="" name="contact-email" class="contact-email"/><span class="email-required"></span></p>
                     <label class="label">Phone:</label>
                     <p><input type="text" value="" name="contact-phone" class="contact-phone"/><span class="phone-required"></span></p>
                     <label class="label">Message</label>
                     <p>
                    <textarea class="contact-commnent" name="comments">
                    </textarea><span class="comment-required"></span></p>
                    <label class="label"></label>
                     <p id="p-submit">
                    <input id="submit-form" class="submit-button" name="submit"type="submit" value="Submit"></p>
                 </form>
                </div>

the javascript is: JavaScript是:

$('#submit-form').click(function(){

     var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
     var names               = $('#contact-form [name="contact-names"]').val();  
   var email_address = $('#contact-form [name="contact-email"]').val();
   var phone = $('#contact-form [name="contact-phone"]').val();
   var comment           = $.trim($('#contact-form .contact-commnent').val());
   var data_html ='' ;


                if(names == ""){
                     $('.name-required').html('Your name is required.');
                }else{
                     $('.name-required').html('');
                }
                if(email_address == ""){
                     $('.email-required').html('Your email is required.');
                }else if(reg.test(email_address) == false){
                     $('.email-required').html('Invalid Email Address.');
                }else{
                     $('.email-required').html('');
                }

                if(phone == ""){
                     $('.phone-required').html('Your Phone Number is required.');
                }else{
                     $('.phone-required').html('');
                }

                if(comment == ""){
                     $('.comment-required').html('Comment is required.');
                }else{
                     $('.comment-required').html('');
                }

        if(comment != "" && names != "" && reg.test(email_address) != false){

            data_html = "names="+ names + "&comment=" + comment + "&email_address="+ email_address;

            //alert(data_html);

          $.ajax({
                  type: 'POST',
                  url: 'contact-send.php',
                  data: data_html,
                  success: function(msg){
                    if (msg == 'sent'){
                            $('#success').html('Your Message Has Been Sent We Will Be In Touch Soon')   ;
                            $('#contact-form [name="contact-names"]').val('');   
                          $('#contact-form [name="contact-email"]').val('');
                          $('#contact-form [name="contact-phone"]').val('');
                        $('#contact-form .contact-commnent').val('');

                        }else{
                            $('#success').html('Mail Error. Please Try Again.!')    ;   
                        }
                  }
            });

      }

        return false;
    });

The PHP is: PHP是:

<?php
 $names = $_POST['names'];
 $email = $_POST['email_address'];
 $phone = $_POST['phone'];
 $comment = $_POST['comment'];
 $to ='EMAIL ADDRESS GOES HERE REMOVED';

 $message = "";
 $message .= "Name: " . htmlspecialchars($names, ENT_QUOTES) . "<br>\n";
 $message .= "Email: " . htmlspecialchars($email, ENT_QUOTES) . "<br>\n";
 $message .= "Phone: " . htmlspecialchars($phone, ENT_QUOTES) . "<br>\n";
 $message .= "Message: " . htmlspecialchars($comment, ENT_QUOTES) . "<br>\n";
 $lowmsg = strtolower($message);

 $headers = "MIME-Version: 1.0\r\nContent-type: text/html; charset=iso-8859-1\r\n";
 $headers .= "From: \"" . $names . "\" <" . $email . ">\r\n";
 $headers .= "Reply-To: " .  $email . "\r\n";
 $message = utf8_decode($message);  mail($to, "Note from the Contact Form", $message, $headers);

 if ($message){
        echo 'sent';
 }else{
      echo 'failed';
 }
?>

If someone can see something I have missed I would be very grateful I have been looking at this for ages and can't see what I am missing. 如果有人能看到我想念的东西,我将不胜感激,多年来我一直在寻找这个东西,看不到我想念的东西。

data_html = "names="+ names + "&comment=" + comment + "&email_address="+ email_address;

此行是您要发布到服务器的数据,但是好像您忘记了附加电话号码!

use: 采用:

data_html = "names="+ names + "&comment=" + comment + 
            "&email_address="+ email_address + "&phone=" + phone;

instead of: 代替:

data_html = "names="+ names + "&comment=" + comment + 
            "&email_address="+ email_address;

You are missing to attach phone variable! 您缺少附加电话变量!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM