我正在处理联系表单,而且代码似乎无法正常工作。我提交时无法获得验证,我无法查看用户提交的内容,而且表单根本没有安全性。这是我到目前为止所生产的,它完成了大部分工作,我不能按照我想要的方式工作。有人可以帮我这个:
编辑: 我正在制作联系表格以收集儿童保育网站的输入(我只需要父母的姓名,电子邮件,电话号码和有关孩子的信息)。我希望在访问者/家长提交时,向我发送表格已提交的验证,并获得他们提交给我的内容的副本。提交表单的父母也应该获得表单提交的验证。当输入表格时,页面重置,我没有得到他们的输入副本,父母也没有得到验证.. - Suppahman 4分钟前编辑
我希望它能向我发送提交表格的验证,我会得到一份输入的副本,以便我以后可以联系他们,父母会得到我得到的证明,并且表格应该是安全的,以便没人能骗我。目前,形式基本上......好......死了。你们有没有机会帮助我?我不知道我是否正确回答了你的问题,但我认为应该这样做?
PHP
$contactname = $_POST["contact-name"];
$contactemail = $_POST["contact-email"];
$contactphone = $_POST["contact-phone"];
$child_info = $_POST["child_info"];
$to = 'maemail@gmail.com';
$subject = 'Contact Form Submission!';
//******************************************************************************************************************************//
if(isset($_POST['email'])) {
$to = "maemail@gmail.com";
$subject = "Contact Form Submission";
function died($error)
{
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error . "<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
if(!isset($_POST['contact-name']) || !isset($_POST['contact-email']) || !isset($_POST['contact-phone']) || !isset($_POST['child-info'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$contactname = $_POST['contact-name']; //required
$contactemail = $_POST['contact-email']; //required
$contactphone = $_POST['contact-phone']; //required
$child_info = $_POST['child_info']; //required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp, $contactemail)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
$numb_exp = '/^[0-9.-]';
if(!preg_match($string_exp, $contactname)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($numb_exp, $contactphone)) {
$error_message .= 'The Phone Number you entered does not appear to be valid.<br />';
}
if(strlen($child_info) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string)
{
$bad = array(
"content-type",
"bcc:",
"to:",
"cc:",
"href"
);
return str_replace($bad, "", $string);
}
$email_message .= "First Name: " . clean_string($contactname) . "\n";
$email_message .= "Email: " . clean_string($contactemail) . "\n";
$email_message .= "Telephone: " . clean_string($contactphone) . "\n";
$email_message .= "Child Information: " . clean_string($child_info) . "\n";
$headers = 'From: ' . $contactemail . "\r\n" . 'Reply-To: ' . $contactemail . "\r\n" . 'X-Mailer: PHP/' . phpversion();
@mail($to, $subject, $email_message, $headers);
echo "Thank you for contacting us. We will be in touch with you very soon.";
}
//******************************************************************************************************************************//
$v1 = "
<html> <body> <style>
h1 {color:#000066;}
table {border:1px solid black; background: #e3f0ff;}
</style> <h1>Hello, this form has been submitted!</h1> <img src= 'logo1.png' /> <table rules='all' style='border-color: #ffb300;' cellpadding='10' width='500px'> <tr style='background: #ffb300;'><td>First Name: $contactname</td> <tr style='background: #fafafa;'><td>Email: $contactemail</td> <tr style='background: #fafafa;'><td>Phone: $contactphone</td><tr style='background: #fafafa;'><td>Child Information: $child_info</td></table> </body> </html> ";
$message = $v1;
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
echo "Message has been sent..."; //Page RE DIRECT
echo $v1;
//******************************************************************************************************************************//
$contactname = $_POST["contact-name"];
$contactemail = $_POST["contact-email"];
$contactphone = $_POST["contact-phone"];
$child_info = $_POST["child_info"];
$verificationmsg = 'Thank you for your inquiry, we will contact you shortly! <br>Best,<br>Me<br>©Hi LOGO WENT HERE(TM) All Rights Reserved 2015';
$subject = 'Message Confirmed!';
$v1 = "
<html> <body> <style>
#disclosure {font-size: 8px; color: #333;}
h1 {color:#000066;}
table {border:1px solid black;}
</style> <img src= 'logo1.png' /> <table rules='all' style='border-color: #ffb300;' cellpadding='10' width='500px'> <tr style='background: #ffb300;'><td>Email Confirmation <tr style='background: #fafafa;'><td>Hello $contactname, your message has been recieved! We will contact you shortly! <br><br>Best, <br>M<br>©M(TM) All Rights Reserved 2015 </div> </table> </body> </html> ";
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
mail($contactemail, $subject, $verificationmsg, $headers);
$count = count(file("formsubmissions.csv"));
$today = date("d M Y h:i A");
echo $today;
echo $v1;
$cvsData = "\n" . $count . "," . $today . "," . $contactname . "," . $contactemail . "," . $contactphone . "," . $child_info;
$fp = fopen("formsubmissions.csv", "a");
if($fp) {
fwrite($fp, $cvsData);
fclose($fp);
}
HTML
<form action="contact.php" class="footer-form" method="post">
<p class="title">How can we be of service?</p>
<div class="form-group">
<strong>
<input type="text" class="form-control" name="contact-name" id="contact-name" placeholder="Name:">
</strong>
</div>
<div class="form-group">
<strong>
<input type="email" class="form-control" name="contact-email" id="contact-email" placeholder="E-mail:">
</strong>
</div>
<div class="form-group">
<strong>
<input type="phone" class="form-control" name="contact-phone" id="contact-phone" placeholder="Phone:">
</strong>
</div>
<div class="form-group">
<strong>
<input type="text" class="form-control" name="child_info" id="child_info" placeholder="Tell us about your child:">
</strong>
</div>
<button type="submit" class="btn btn-default waves-effect waves-button waves-float waves-classic"><strong>Submit</strong></button>
</form>