Php 子目录中HTML文件的不同表单输出

Php 子目录中HTML文件的不同表单输出,php,html,forms,Php,Html,Forms,我已经写了一个相当直接的html表单,当提交表单时,将使用一个单独的php文件进行处理 php使用表单字段中的数据生成预订确认PDF,将其附加到电子邮件,然后发送电子邮件 当我的HTML表单页面位于根目录中时,例如website.com/booking.HTML它会按预期工作。它接受表格,发送附有pdf的电子邮件;没问题 但是,如果我将其移动到一个目录中,例如website.com/book/,它将返回输出: D:\Web\网站名称 我想我一定错过了一些基本的东西 有人能告诉我为什么我会在子目录

我已经写了一个相当直接的
html
表单,当提交表单时,将使用一个单独的
php
文件进行处理

php
使用表单字段中的数据生成预订确认
PDF
,将其附加到电子邮件,然后发送电子邮件

当我的
HTML
表单页面位于根目录中时,例如
website.com/booking.HTML
它会按预期工作。它接受表格,发送附有
pdf
的电子邮件;没问题

但是,如果我将其移动到一个目录中,例如
website.com/book/
,它将返回输出:

D:\Web\网站名称

我想我一定错过了一些基本的东西

有人能告诉我为什么我会在子目录中收到不同的输出吗

下面是PHP文件的完整代码

<?=
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
require_once "$root/PHPMailer/PHPMailerAutoload.php";

$results_messages = array();

$mail = new PHPMailer(true);
$mail->CharSet = 'utf-8';

class phpmailerAppException extends phpmailerException {}

try {
$to = $_POST['email'];
if(!PHPMailer::validateAddress($to)) {
  throw new phpmailerAppException("Email address " . $to . " is invalid -- aborting!");
}
$mail->isSMTP();
$mail->SMTPDebug  = 0;
$mail->Host       = "relay.examplehost.com";
$mail->Port       = "25";
$mail->SMTPSecure = "none";
$mail->SMTPAuth   = false;
$mail->addReplyTo($_POST['email'], $_POST['realname']);
$mail->From       = "example@example.com";
$mail->FromName   = "Website name";
$mail->addAddress($_POST['email'], $_POST['realname']);
$mail->addBCC("example@example.com", "Enquiries");
$mail->Subject  = "Website Booking Details";

isset($_POST['checkbox1']) && $vehicle = $_POST['checkbox1'];
isset($_POST['checkbox2']) && $vehicle = isset($vehicle) ? $vehicle . ", " . $_POST['checkbox2'] : $_POST['checkbox2'];
isset($_POST['checkbox3']) && $vehicle = isset($vehicle) ? $vehicle . ", " . $_POST['checkbox3'] : $_POST['checkbox3'];
isset($_POST['checkbox4']) && $vehicle = isset($vehicle) ? $vehicle . ", " . $_POST['checkbox4'] : $_POST['checkbox4'];
isset($_POST['checkbox5']) && $vehicle = isset($vehicle) ? $vehicle . ", " . $_POST['checkbox5'] : $_POST['checkbox5'];
isset($_POST['checkbox6']) && $vehicle = isset($vehicle) ? $vehicle . ", " . $_POST['checkbox6'] : $_POST['checkbox6'];
isset($_POST['checkbox7']) && $vehicle = isset($vehicle) ? $vehicle . ", " . $_POST['checkbox7'] : $_POST['checkbox7'];
isset($_POST['checkbox8']) && $vehicle = isset($vehicle) ? $vehicle . ", " . $_POST['checkbox8'] : $_POST['checkbox8'];

// Check for bots
if (strcmp($_POST['checkme'], 'robot')== 0) {
    isset($_POST['redirect']) ? $location = $_POST['redirect'] : $location = "thanks.html";
    header('Location: ' . $location);
     exit;
}

// Convert form data into PDF
require("../fpdf/fpdf.php");
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial');
$pdf->Image('images/emailheader.jpg');
$pdf->Ln(10);
$pdf->Cell(0,10,"Booking Form",0,1,'L');
$pdf->SetFont('Arial');
$pdf->Cell(0,10,"Name: {$_POST['realname']}",0,1,'L');
$pdf->Cell(0,10,"Company Name: {$_POST['company-name']}",0,1,'L');
$pdf->Cell(0,10,"Address: {$_POST['Address']}",0,1,'L');
$pdf->Cell(0,10,"Billing Address: {$_POST['billing-address']}",0,1,'L');
$pdf->Cell(0,10,"Telephone: {$_POST['Telephone']}",0,1,'L');
$pdf->Cell(0,10,"Email: {$_POST['email']}",0,1,'L');
$pdf->Cell(0,10,"Deposit Payment: {$_POST['deposit-payment']}",0,1,'L');
$pdf->Cell(0,10,"Vehicle Type: {$_POST['vehicle-type']}",0,1,'L');
$pdf->Cell(0,10,"Driver Name: {$_POST['driver1-name']}",0,1,'L');
$pdf->Cell(0,10,"Driver NI: {$_POST['driver1-NI-number']}",0,1,'L');
$pdf->Cell(0,10,"Driver Licence No: {$_POST['driver1-licence-no']}",0,1,'L');
$pdf->Cell(0,10,"Driver Licence EXP Date: {$_POST['driver1-licence-exp-date']}",0,1,'L');
$pdf->Cell(0,10,"Licence Check Code: {$_POST['driver1-licence-check-code']}",0,1,'L');
$pdf->Cell(0,10,"Driver Passport no: {$_POST['driver1-passport-no']}",0,1,'L');
$pdf->Cell(0,10,"Driver Passport Exp Date: {$_POST['driver1-passport-exp-date']}",0,1,'L');
$pdf->Cell(0,10,"Driver 2 Name: {$_POST['driver2-name']}",0,1,'L');
$pdf->Cell(0,10,"Driver 2 NI Number: {$_POST['driver2-NI-number']}",0,1,'L');
$pdf->Cell(0,10,"Driver 2 Licence no: {$_POST['driver2-licence-no']}",0,1,'L');
$pdf->Cell(0,10,"Driver 2 licence exp date: {$_POST['driver2-licence-exp-date']}",0,1,'L');
$pdf->Cell(0,10,"Driver 2 licence check code: {$_POST['driver2-licence-check-code']}",0,1,'L');
$pdf->Cell(0,10,"Delivery location: {$_POST['delivery-location']}",0,1,'L');
$pdf->Cell(0,10,"Delivery Date: {$_POST['delivery-date']}",0,1,'L');
$pdf->Cell(0,10,"Delivery Time: {$_POST['delivery-time']}",0,1,'L');
$pdf->Cell(0,10,"Collection Location: {$_POST['collection-location']}",0,1,'L');
$pdf->Cell(0,10,"Collection Date: {$_POST['collection-date']}",0,1,'L');
$pdf->Cell(0,10,"Collection Time: {$_POST['collection-time']}",0,1,'L');
$pdf->Cell(0,10,"Arrival Flight No: {$_POST['arrival-flight-no']}",0,1,'L');
$pdf->Cell(0,10,"Arrival Flight time: {$_POST['arrival-flight-time']}",0,1,'L');
$pdf->Cell(0,10,"Departure Flight No: {$_POST['departure-flight-no']}",0,1,'L');
$pdf->Cell(0,10,"Departure Flight Time: {$_POST['departure-flight-time']}",0,1,'L');
$pdf->Cell(0,10,"More Info: {$_POST['more-info']}",0,1,'L');

$pdf->output('bookings/booking.pdf','F'); 

// Email body
$body = <<<EOT
<a href="https://www.example.com"><img src="https://example.com/images/emailheader.jpg"></a>
<br>
<br>
<table width="660" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><p><font size="2" face="Arial, Helvetica, sans-serif">Thank you; {$_POST['realname']}</font></p>
      <p align="justify"><font size="2" face="Arial, Helvetica, sans-serif">We have received your booking details and will contact you shortly. The auto response e-mail verifies your details as supplied. Please make sure you entered your e-mail address and details correctly as this ensures we can respond to your request effectively.<br>
  <br>
  Regards</font></p>
      <p><font size="2" face="Arial, Helvetica, sans-serif"> Sales Team <br></font></p>
      <p> <font size="2" face="Arial, Helvetica, sans-serif"> Information posted as attached</font></p></td>
  </tr>
</table>
EOT;


$file_to_attach = 'bookings/booking.pdf';

$mail->WordWrap = 78;
$mail->msgHTML($body, dirname(__FILE__), true);

//attach the booking form pdf
$mail->AddAttachment( $file_to_attach , 'booking.pdf' );

  //Create message bodies and embed images
// $mail->addAttachment('images/phpmailer_mini.png','phpmailer_mini.png');  // optional name
// $mail->addAttachment('images/phpmailer.png', 'phpmailer.png');  // optional name

try {
  $mail->send();
  $results_messages[] = "Message has been sent using SMTP";
}
catch (phpmailerException $e) {
  throw new phpmailerAppException('Unable to send to: ' . $to. ': '.$e->getMessage());
}
}
catch (phpmailerAppException $e) {
  $results_messages[] = $e->errorMessage();
}

isset($_POST['redirect']) ? $location = $_POST['redirect'] : $location = "thanks.html";
header('Location: ' . $location);

//delete PDF from webspace
unlink ('bookings/booking.pdf');

?>


我们需要查看一些代码才能帮助您。显示执行处理的PHP文件中的代码。抱歉,没问题。我已经更新了帖子,在底部添加了代码。我用示例替换了所有真实的web地址和电子邮件地址。您所说的“它返回输出:
D:\web\Website Name
”是什么意思?您是否将其作为生成的PDF文件的内容?它是否显示在浏览器地址栏中?完全不同的东西?@CBroe这一行是在网页顶部的网页浏览器中输出的,网页内容应该在那里。当这种情况发生时,它不会发送电子邮件或生成PDF,似乎不会走那么远。我们需要看到一些代码来帮助您。显示PHP文件中进行处理的代码。抱歉,没有问题。我已经更新了帖子,在底部添加了代码。我用示例替换了所有真实的web地址和电子邮件地址。您所说的“它返回输出:
D:\web\Website Name
”是什么意思?您是否将其作为生成的PDF文件的内容?它是否显示在浏览器地址栏中?完全不同的东西?@CBroe这一行是在网页顶部的网页浏览器中输出的,网页内容应该在那里。当这种情况发生时,它不会发送电子邮件或生成PDF,似乎不会走那么远。