简体   繁体   English

php,javascript:ajax表单电子邮件操作和验证

[英]php,javascript:ajax Form email action and validation

I have tried using a action="mail.site.com", info@site.com, and the page just refreshes without sending the query form.I think I need a PHP or Ajax page to send the email to the server and give the user a response. 我尝试使用action =“ mail.site.com”,info@site.com,并且页面只是刷新而不发送查询表单。我认为我需要一个PHP或Ajax页面才能将电子邮件发送到服务器并提供用户的回应。 I have tried a few things I am not skilled at PHP. 我已经尝试了一些我不懂PHP的东西。 If anyone has any insight it would be greatly appreciated. 如果有人有任何见识,将不胜感激。 Thank You. 谢谢。

 <section style="background: url(_images/pattern.html)" class="reservation parallax-repeat dark"> <div class=reservation__inner> <div class=container> <div class=row> <div class="col-sm-8 col-lg-6 col-sm-offset-2 col-lg-offset-3 text-center"> <header class=section-header> <h2>Servicio de reservas</h2> <div class=divider></div> <p> Para que el mantenimiento de su vehículo sea rápido y sin complicaciones, le recomendamos encarecidamente que realice una reserva en línea. Es completamente gratis y no te llevará mucho tiempo.</header> </div> </div> <div class=reservation-form> <form id=reservForm action=# method=POST data-toggle=validator> <div class=reservation-form__center-wrapper> <div class="form-group item-1"> <label for=resName class=label-control>Tu Nombre</label> <div class="input-wrap input-wrap--icon-left"><i class="input-icon pe-7s-user"></i> <input id=resName type=text name=field_name placeholder="David Kraemer" required class=form-control> </div> </div> <div class="form-group item-2"> <label for=resNumber class=label-control>Su Teléfono</label> <div class="input-wrap input-wrap--icon-left"><i class="input-icon pe-7s-phone"></i> <input id=resNumber type=tel name=field_tel placeholder="+1 (812) 281 55 23" required class=form-control> </div> </div> <div class="form-group item-3"> <label for=resDate class=label-control>Fecha</label> <div class="input-wrap input-wrap--icon-left"><i class="input-icon pe-7s-date"></i> <input id=resDate type=text name=field_date placeholder=09/18/2016 required class="form-control pick-date"> </div> </div> <div class="form-group item-4"> <label for=resTime class=label-control>Hora</label> <div class=input-wrap><i class="input-icon fa fa-caret-down"></i> <input id=resTime type=text name=field_time placeholder=16:30 required class="form-control time-pick"> </div> </div> </div> <button type=submit class="btn btn-regular btn-accent"><span class=btn-text> Hacer una reserva</span><span class=btn-over></span></button> </form> </div> </div> </div> </section> 

I can see that you have the html form constructed, the part you are missing will be adding the url where the form data will be processed. 我可以看到您已经构造了html表单,缺少的部分将添加将在其中处理表单数据的url。

<form id=reservForm action="sendemail.php" method=POST data-toggle=validator>

Once done you need to create a sendemail.php file and to access the user data that the user keyed the php code will look like this: 完成后,您需要创建一个sendemail.php文件并访问用户键入php代码的用户数据,如下所示:

<?php
    $name = $_POST['field_name'];
    $tel = $_POST['field_tel'];
    $date = $_POST['field_date'];
    $time = $_POST['field_time'];
?>

After obtaining the data, you need to validate each of them to see if the type formats is what you want. 获取数据后,您需要验证它们中的每一个,以查看类型格式是否符合您的要求。 Try reading form validation 尝试阅读表单验证

Last but not least, if everything is alright then you can proceed to send the email using the sample code below: 最后但并非最不重要的一点是,如果一切正常,那么您可以使用以下示例代码继续发送电子邮件:

<?php

  $to = "abc@domain.com";
  $headers = "From: $email_from \r\n";
  $headers .= "Reply-To: $visitor_email \r\n";
  mail($to,$email_subject,$email_body,$headers);

?>

You can read more about sending email here . 您可以在此处阅读有关发送电子邮件的更多信息。

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

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