开发者

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.

The HTML form is below:

            <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:

$('#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
 $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;

This line is the data you're posting to the server, but it looks like you're forgetting to attach the phone number!


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜