javascript - JQuery Ajax Form sends 2 email -
anyone knows why receive 2 emails instead of 1???
i'm new jquery , ajax, in code working sending 2 email each time.
html
<form class="well form-horizontal" action=" " method="post" id="contact_form"> <fieldset> ... <!-- mensaje enviado con exito --> <div class="alert alert-success" role="alert" id="success_message">tu mensaje se ha enviado con exito <i class="glyphicon glyphicon-thumbs-up"></i> gracias por contactar con nosotros, en breve responderemos tu mensaje.</div> <!-- boton submit --> <div class="form-group"> <div class="col-md-12 derecha"> <button type="submit" name="submit" class="btn btn-warning">enviar <span class="glyphicon glyphicon-send"></span> </button> </div> </div> </fieldset> </form>
javascript
$(document).ready(function() { $('#contact_form').bootstrapvalidator({ ... }) var form = $('#contact_form'); // contact form // form submit event form.on('submit', function(e) { e.preventdefault(); // prevent default form submit $.ajax({ url: 'enviar.php', // form action url type: 'post', // form submit method get/post datatype: 'html', // request type html/json/xml data: form.serialize(), // serialize form data success: function(data) { $('#success_message').slidedown({ opacity: "show" }, "slow"); $('#contact_form').data('bootstrapvalidator').resetform(); }, error: function(e) { console.log(e) } }); }); });
and php
<?php if (!$_post){ ?> <p>no se ha recibido ningĂșn dato</p> <?php } else { ... if (mail($destinatario, $asunto, $cuerpo, $headers)) { echo ("ok"); }; } ?>
thank in advance!!!
Comments
Post a Comment