我在使用PHP构建的复杂表单中遇到问题。 表单和进程在同一页面中,因为它在bootstrap模式中加载,并在同一页面中显示结果。提交表单后,它会使用html2pdf创建PDF格式的凭证,并向客户端和两位管理员发送电子邮件。
问题是没有从表单中发送任何结果。它将电子邮件发送给管理员,客户端不会收到空白空间。没有从表单中获取姓名,号码或电子邮件。
在表单工作的过程之下。
<?php
require_once(dirname(__FILE__).'/html2pdf/html2pdf.class.php');
?>
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "one@email.com,two@email.com";
$email_client = $email;
$email_subject = "3Booking";
function died($error) {
// your error code can go here
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();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['number']) ||
!isset($_POST['optionsRadios']))
{
died('We are sorry, but there appears to be a problem with the form you submitted.');
$name = $_POST['name']; // required
$email = $_POST['email']; // required
$number = $_POST['number']; // required
$optionsAreas = $_POST['optionsAreas']; // not required
$optionsRadios = $_POST['optionsRadios']; // not required
$newsletter = $_POST['newsletter'];
$ref = $_POST['ref'];
}
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= "The Email Address you entered does not appear to be valid.<br />";
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($number) < 2) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$optionsRadios)) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(!preg_match($string_exp,$newsletter)) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$datei = fopen("library/countlog.txt","r");
$count = fgets($datei,1000);
fclose($datei);
$ref="3COMPAREWLC".$count."-".date('ymd');
$numlink = '3COMPAREWLC'.$count.'-'.date('ymd');
$name = $name;
$email_message ="<body style='background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;'>
<div style='background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;'>
<table cellspacing='0' cellpadding='0' border='0' height='100%' width='100%'>
<tr>
<td align='center' valign='top' style='padding:20px 0 20px 0'>
<!-- [ header starts here] -->
<table bgcolor='FFFFFF' cellspacing='0' cellpadding='10' border='0' width='650' style='border:1px solid #E0E0E0;'>
<tr>
<td valign='top'>
<a href='http://super8.pt/3compare/'><img src='http://super8.pt/3compare/library/images/3compare_logo.jpg' alt='3COMPARE' style='margin-bottom:10px;' border='0'/></a></td>
</tr>
<!-- [ middle starts here] -->
<tr>
<td valign='top'>
<h1 style='font-size:22px; font-weight:normal; line-height:22px; margin:0 0 11px 0;'>New Reservation</h1>
<p style='font-size:12px; line-height:16px; margin:0 0 16px 0;'>A new reservation was made on the website 3COMPARE</p>
<p style='border:1px solid #E0E0E0; font-size:12px; line-height:16px; margin:0; padding:13px 18px; background:#f9f9f9;'>
Personal Info <br/>
<strong>Reference:</strong> ".clean_string($ref)."<br/>
<strong>Name:</strong> ".clean_string($name)."<br/>
<strong>Email:</strong> ".clean_string($email)."<br/>
<strong>Mobile Number:</strong> ".clean_string($number)."<br/>
<strong>Payment Method:</strong> ".clean_string($optionsRadios)."<br/>
<strong>Newsletter:</strong> ".clean_string($newsletter)."<p>
<p style='font-size:12px; line-height:16px; margin:0 0 8px 0;'>Laser Hair Loss Therapy:<br/>
30-minute session per week for three months, with 13 sessions in total.</p>
<p style='border:1px solid #E0E0E0; font-size:12px; line-height:16px; margin:0; padding:13px 18px; background:#f9f9f9;'>".$optionsAreas."</p>
<p style='font-size:12px; line-height:16px; margin:0;'></p>
<p style='border:1px solid #E0E0E0; font-size:12px; line-height:16px; margin:0; padding:13px 18px; background:#f9f9f9;'>
<a href='http://super8.pt/3compare/voucher/ticket".$numlink.".pdf'>Click here to download and print your voucher</a>
</p>
</td>
</tr>
<tr>
<td bgcolor='#EAEAEA' align='center' style='background:#EAEAEA; text-align:center;'><center><p style='font-size:12px; margin:0;'><strong>3COMPARE</strong></p></center></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";
@mail($email_to, $email_subject, $email_message, $headers);
@mail($email_client, $email_subject, $email_message, $headers);
ob_start();
$num = '3COMPAREWLC'.$count.'-'.date('ymd');
$nom = $name;
$date = '2014/07/31';
?>
<style type="text/css">
<!--
div.zone { border: none; border-radius: 6mm; background: #FFFFFF; border-collapse: collapse; padding:3mm; font-size: 2.7mm;}
h1 { padding: 0; margin: 0; color: #DD0000; font-size: 7mm; }
h2 { padding: 0; margin: 0; color: #222222; font-size: 5mm; position: relative; }
-->
</style>
<page format="100x200" orientation="L" backcolor="#f0a804" style="font: arial;">
<div style="rotate: 90; position: absolute; width: 100mm; height: 4mm; left: 195mm; top: 0; font-style: italic; font-weight: normal; text-align: center; font-size: 2.5mm;">
This is your e-ticket to present at the Clinic
</div>
<table style="width: 99%;border: none;" cellspacing="4mm" cellpadding="0">
<tr>
<td colspan="2" style="width: 100%">
<div class="zone" style="height: 34mm;position: relative;font-size: 5mm;">
<div style="position: absolute; right: 3mm; top: 3mm; text-align: right; font-size: 4mm; ">
<b><?php echo $nom; ?></b><br>
</div>
<div style="position: absolute; right: 3mm; bottom: 3mm; text-align: right; font-size: 4mm; ">
<b>Weight Loss Clinic</b><br>
Reference : <b><?php echo $num; ?></b><br>
Booked at : <b><?php echo date('d/m/Y à H:i:s'); ?></b><br>
</div>
<h1>VOUCHER</h1>
<b>Valid until <?php echo $date; ?></b><br>
<img src="library/images/3compare_logo.jpg" width="233" height="65" alt="logo" style="margin-top: 3mm; margin-left: 20mm">
</div>
</td>
</tr>
<tr>
<td style="width: 25%;">
<div class="zone" style="height: 40mm;vertical-align: middle;text-align: left;">
<b><?php echo $optionsAreas; ?></b>
</div>
</td>
<td style="width: 75%">
<div class="zone" style="height: 40mm;vertical-align: middle; text-align: justify">
<b>Personal Info</b><br>
<strong>Name:</strong> <?php echo $name; ?><br/>
<strong>Email:</strong> <?php echo $email; ?><br/>
<strong>Mobile Number:</strong> <?php echo $number; ?><br/>
<strong>Payment Method:</strong> <?php echo $optionsRadios; ?><br/>
<p style="font-size:10px; line-height:12px; margin:0 0 8px 0;"><b>Laser Hair Loss Therapy:</b><br/>
30-minute session per week for three months, with 13 sessions in total.</p>
</div>
</td>
</tr>
</table>
</page>
<?php
$content = ob_get_clean();
// convert
try
{
$html2pdf = new HTML2PDF('P', 'A4', 'fr', true, 'UTF-8', 0);
$html2pdf->pdf->SetDisplayMode('fullpage');
$html2pdf->writeHTML($content, isset($_GET['vuehtml']));
$html2pdf->Output('voucher/ticket'.$num.'.pdf','F');
}
catch(HTML2PDF_exception $e) {
echo $e;
exit;
}
?>
<!-- include your own success html here -->
<div class="container orange-bg">
<p><div class="alert alert-success">Thank you for booking at 3COMPARE. We will be in touch with you very soon. <a class="btn btn-warning btn-shadow" href="<?php echo 'voucher/ticket'.$num.'.pdf'?>"><strong>Download your Voucher</strong> <i class="fa fa-arrow-circle-down"></i></a></div></p>
</div>
<?php
/* counter */
//opens countlog.txt to read the number of hits
$datei = fopen("library/countlog.txt","r");
$count = fgets($datei,1000);
fclose($datei);
$count=$count + 1 ;
// opens countlog.txt to change new hit number
$datei = fopen("library/countlog.txt","w");
fwrite($datei, $count);
fclose($datei);
?>
<?php
}
?>
表格在下面
<form class="form-horizontal marginform" role="form" action="<?php $_SERVER['PHP_SELF']?>" method="POST" name="contact" id="contact">
<div class="row">
<div class="col-md-4 white-box wborder-box">
<?php
$onearea .= "Order Details <br/>
<strong>Duration:</strong> 45 mins<br/>
<strong>Employee:</strong> Cristina @ HDC<br/>
<strong>SubTotal:</strong> £85.00<br/>
<strong>Total</strong>: £85.00<br/>
<strong>Valid until</strong>: 2014-07-31<br/>";
$twoareas .= "Order Details <br/>
<strong>Duration:</strong> 45 mins<br/>
<strong>Employee:</strong> Cristina @ HDC<br/>
<strong>SubTotal:</strong> £165.00<br/>
<strong>Total</strong>: £165.00<br/>
<strong>Valid until</strong>: 2014-07-31<br/>";
?>
<h5>Order Details</h5>
<div class="radio-inline areasform">
<label for="optionsAreas1" name="oa1label" class="control-label">One Area</label>
<input type="radio" name="optionsAreas" id="optionsAreas1" value="<?php echo ($onearea); ?>">
</div>
<div class="radio-inline areasform">
<label for="optionsAreas2" class="control-label">Two Areas</label>
<input type="radio" name="optionsAreas" id="optionsAreas2" value="<?php echo $twoareas ?>">
</div>
<p><strong>Cryogenic Lipolysis Therapy</br>45-minute session per week for three months, with 13 sessions in total.</strong></p>
<div id="hideOneArea">
<h5>One Area</h5>
<dl class="dl-horizontal">
<dt><small>Duration</small></dt>
<dd><small>45 mins</small></dd>
<dt><small>Employee</small></dt>
<dd><small>Cristina @ HDC</small></dd>
<dt><small>SUBTOTAL</small></dt>
<dd><small>£85.00</small></dd>
<dt><small>TOTAL</small></dt>
<dd><small>£85.00</small></dd>
</dl>
</div>
<div id="hideTwoAreas">
<h5>Two Areas</h5>
<dl class="dl-horizontal">
<dt><small>Duration</small></dt>
<dd><small>45 mins</small></dd>
<dt><small>Employee</small></dt>
<dd><small>Cristina @ HDC</small></dd>
<dt><small>SUBTOTAL</small></dt>
<dd><small>£165.00</small></dd>
<dt><small>TOTAL</small></dt>
<dd><small>£165.00</small></dd>
</dl>
</div>
<p><strong>Payment method:</strong></p>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios1" value="Pay At Clinic" checked>Pay At Clinic
</label>
</div>
<div class="radio">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="Other Way" class="hidden">
</div>
<p><strong>Available until: 2014-07-31</strong></p>
<input name="ref" type="hidden" value="<?php $datei = fopen("library/countlog.txt","r");
$count = fgets($datei,1000);
fclose($datei);echo "3COMPAREWLC".$count."-".date('ymd');?>">
</div>
<div class="col-md-8">
<div class="row">
<div class="col-md-12 white-box wborder-box">
<h5>Your contact details</h5>
<div class="form-group">
<label for="inputEmail3" class="col-sm-4 control-label"><small>Your full name*</small></label>
<div class="col-sm-8">
<input type="text" name="nome" class="form-control" id="inputEmail3" placeholder="Full Name" required>
</div>
</div>
<div class="form-group">
<label for="inputPassword3" class="col-sm-4 control-label"><small>Your email address*</small></label>
<div class="col-sm-8">
<input type="email" name="email" class="form-control" id="inputPassword3" placeholder="Email" required>
</div>
</div>
<div class="form-group">
<label for="number" class="col-sm-4 control-label"><small class="redtext">Mobile</small> <small>Number*</small></label>
<div class="col-sm-6">
<input type="tel" name="number" class="form-control" id="number" placeholder="Mobile Number" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-12 col-xs-12 alinharr">
<button type="submit" name="submit" class="btn btn-lg btn-danger btn-shadow" value="Send">
<div class="row">
<div class="col-sm-8 col-xs-8">
<small class="sizebtn">Click Here to</small></br><strong class="sizebtnlg">Complete Your Order</strong>
</div>
<div class="col-sm-4 col-xs-4">
<i class="fa fa-gift fa-lg fa-3x"></i>
</div>
</div>
</button>
</div>
</div>
<div class="form-group">
<div class="col-sm-12">
<div class="checkbox">
<label>
<input type="checkbox" name="newsletter" value="Yes" id="newsletter" checked> <small>Keep me in the loop about special offers and the latest community news</small>
</label>
<input type="checkbox" class="hidden" name="newsletter" value="No" id="newsletter1">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
这有什么问题?