javascript - Website contact form not receiving messages -
very new html , website developer , unsure why current contact box not working. i'm hosting own website , when attempt send message sent response emails never received.
i have't eliminated email hosting being broken using multiple email addresses send , receive have been unable find source of problem.
see relevant code bellow
main.js
// contact form var form = $('#main-contact-form'); form.submit(function (event) { event.preventdefault(); var form_status = $('<div class="form_status"></div>'); $.ajax({ url: $(this).attr('action'), beforesend: function () { form.prepend(form_status.html('<p><i class="fa fa-spinner fa-spin"></i> email sending...</p>').fadein()); } }).done(function (data) { form_status.html('<p class="text-success">thank contact us. possible contact you</p>').delay(3000).fadeout(); }); }); sendemail.php
<?php $name = @trim(stripslashes($_post['name'])); $from = @trim(stripslashes($_post['email'])); $subject = @trim(stripslashes($_post['name'])); $message = @trim(stripslashes($_post['message'])); $to = '\\myemailaddress//'; $headers = array(); $headers[] = "mime-version: 1.0"; $headers[] = "content-type: text/plain; charset=iso-8859-1"; $headers[] = "from: {$name} <{$from}>"; $headers[] = "reply-to: <{$from}>"; $headers[] = "subject: {$subject}"; $headers[] = "x-mailer: php/".phpversion(); mail($to, $subject, $message, $headers); die; index.html
<div class="col-md-8 col-sm-12"> <div class="contact-form bottom"> <h2>send message</h2> <form id="main-contact-form" name="contact-form" method="post" action="sendemail.php"> <div class="form-group"> <input type="text" name="name" class="form-control" required="required" placeholder="name"> </div> <div class="form-group"> <input type="email" name="email" class="form-control" required="required" placeholder="email id"> </div> <div class="form-group"> <textarea name="message" id="message" required="required" class="form-control" rows="8" placeholder="your text here"></textarea> </div> <div class="form-group"> <input type="submit" name="submit" class="btn btn-submit" value="submit"> </div> </form> </div> </div> thanks in advance!
next issue aren't sending data ajax. using $(formselector).serialize() simplifies gathering data
$.ajax({ url: $(this).attr('action'), //serialize form data , include request data: form.serialize(), beforesend: function () { ... } }).done(function (data) { .... }); currently if did print_r($_post); in php see empty
Comments
Post a Comment