我已经写了一个相当简单的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');
?>