javascript - Contact form not responding -
i'm trying implement basic contact form website comprises of 3 fields: name, email , message. php code i'm working given below:
<?php // fetching values url. $name = $_post['name2']; $email = $_post['email2']; $message = $_post['message2']; $email = filter_var($email, filter_sanitize_email); // sanitizing e-mail. // after sanitization validation performed if (filter_var($email, filter_validate_email)) { $subject = $name; // send html mail, content-type header must set. $headers = 'mime-version: 1.0' . "\r\n"; $headers .= 'content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'from:' . $email. "\r\n"; // sender's email $headers .= 'cc:' . $email. "\r\n"; // carbon copy sender $template = '<div style="padding:50px; color:white;">hello ' . $name . ',<br/>' . '<br/>thank contacting me!<br/><br/>' . 'name:' . $name . '<br/>' . 'email:' . $email . '<br/>' . 'message:' . $message . '<br/><br/>' . 'this contact confirmation mail.' . '<br/>' . 'i\'ll possible .</div>'; $sendmessage = "<div style=\"background-color:#7e7e7e; color:white;\">" . $template . "</div>"; // message lines should not exceed 70 characters (php rule), wrap it. $sendmessage = wordwrap($sendmessage, 70); // send mail php mail function. mail("myemailid@gmail.com", $subject, $sendmessage, $headers); echo "your message has been sent successfully!"; } else { echo "<span>* invalid email *</span>"; } ?>
(obviously replaced myemailid@gmail.com actual email address)
the javascript file calling php code under:
$(document).ready(function() { $("#submit").click(function() { var name = $("#name2").val(); var email = $("#email2").val(); var message = $("#message2").val(); // checking blank fields. if (name == '' || email == '' || message == '') { alert("please fill required fields"); } else { $.post("contact_form.php", { name2: name, email2: email, message2: message, }, function(data) { if (data == "your message has been sent successfully!") { $("#footer-form")[0].reset(); // reset form fields on success. } }); } }); });
when click 'send' button nothing happens. doing wrong here? know it's basic appreciated!
in case helps:
<div class="col-sm-6"> <div class="footer-content"> <form role="form" id="footer-form"> <div class="form-group has-feedback"> <label class="sr-only" for="name2">name</label> <input type="text" class="form-control" id="name2" placeholder="name" name="name2" required> <i class="fa fa-user form-control-feedback"></i> </div> <div class="form-group has-feedback"> <label class="sr-only" for="email2">email address</label> <input type="email" class="form-control" id="email2" placeholder="enter email" name="email2" required> <i class="fa fa-envelope form-control-feedback"></i> </div> <div class="form-group has-feedback"> <label class="sr-only" for="message2">message</label> <textarea class="form-control" rows="8" id="message2" placeholder="message" name="message2" required></textarea> <i class="fa fa-pencil form-control-feedback"></i> </div> <input type="button" id="submit" value="send" class="btn btn-default"> </form> </div> </div>
also, php url on clicking send button under:
/index.html?name2=john+doe&email2=johndoe%40example.com&message2=this+is+a+test+message.
ever since changed button type 'button' instead of 'submit', button doesn't reload page or give me url.
to read form params in php need use $_get. debug @ level. see if you're getting values on server side. also, make sure you're reading values in js. providing html chunk help.
Comments
Post a Comment