I try to solve my error today through the internet. means...for the first time i register into a few forum. until now(night), i still cant found the solution.
What should i do?
i create a booking form with the attachment. But my problem is, i unable to open that attachment(pdf file). after the form send to my email(just testing), then i download it. Here's the problem comes out. 'Unable to open the file. Not a valid PDF file.'
and 1 more thing, this error also comes out after i submit my form.
Warning: fclose(): supplied argument is not a valid stream resource in D:\xampplite\htdocs\borneotours02\booking2.php on line 268
My form will save the data inside database and also will send the it to the person's email(who submit it).
Here's my code:
<? require_once("Connections/pamconnection.php");
$cart_id=session_id();
if($_POST['Submit']=='Submit'){
if(mysql_query("INSERT INTO inquiry_log1 (id, session_id, tour, name, contact, email02, pdf_title, itinerary, date02,class_travel,f_detail, airlines, status, date_posted, time)
VALUES ('', '".$cart_id."',
'".mysql_real_escape_string($_POST['tour'])."',
'".mysql_real_escape_string($_POST['name'])."',
'".mysql_real_escape_string($_POST['contact'])."',
'".mysql_real_escape_string($_POST['email02'])."',
'".mysql_real_escape_string($_POST['pdf_file'])."',
'".mysql_real_escape_string($_POST['itinerary'])."',
'".mysql_real_escape_string($_POST['date02'])."',
'".mysql_real_escape_string($_POST['class_travel'])."',
'".mysql_real_escape_string($_POST['flight_detail'])."',
'".mysql_real_escape_string($_POST['airlines'])."',
1, '".date("Y-m-d")."', '".date("g:i a")."')"))
if($_FILES['pdf_file']!='')
{
$fileatt = $HTTP_POST_FILES['pdf_file']['tmp_name'];
$fileatt_type = $HTTP_POST_FILES['pdf_file']['type'];
$file_name = $HTTP_POST_FILES['pdf_file']['name'];
$ext = substr(strrchr($fileatt_type, "/"), 1);
switch ( $ext )
{
case 'pdf':
$fileatt_name = $file_name;
break;
case 'msword':
$fileatt_name = $file_name;
break;
case 'vnd.openxmlformats-officedocument.wordprocessingml.document':
$fileatt_name = $file_name;
break;
}
}
$email_from = $_POST['email02']; // Who the email is from
$email_subject = "Outbound Booking Form"; // The Subject of the email
$email_message.='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<!--<style>
.title{ font-family:Verdana, Arial, Helvetica, sans-serif; font-size:14px; font-weight:bold; }
.content{ font-family:Verdana, Arial, Helvetica, sans-serifl; font-size:12px;}
</style>-->
<body>
<table width="600" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr><td>
<table width="100%" border="0" align="center" cellpadding="4" cellspacing="6" bgcolor="#DCE1E9" class="content">
<tr>
<td colspan="2" class="title">Online Booking Form</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2" align="right">'.date("jS F Y").'</td>
</tr>
<tr class="style9">
<td> </td>
</tr>';
if($_POST['tour']!=''){
$email_message.='<tr class="style9">
<td width="32%" class="title02">Tour Package Name</td>
<td width="68%" class="email_message">'.$_POST['tour'].'</td>
</tr>';}
$email_message.='
<tr class="style9"><td colspan="2" class="title" bgcolor="#FFFFFF"><strong>CONTACT DETAILS</strong></td></tr>';
if($_POST['name']!=''){
$email_message.='<tr class="style9">
<td width="32%" class="title02">Name</td>
<td width="68%" class="email_message">'.$_POST['name'].'</td>
</tr>';}
if($_POST['contact']!=''){
$email_message.='<tr class="style9">
<td class="title02">Contact Person</td>
<td class="email_message">'.$_POST['contact'].'</td>
</tr>';}
if($_POST['email02']!=''){
$email_message.='<tr class="style9">
<td class="title02">Email Address</td>
<td class="email_message">'.$_POST['email02'].'</td>
</tr>';}
$email_message.='
<tr class="style9"><td colspan="2" class="title" bgcolor="#FFFFFF"><strong>ITINERARY</strong></td></tr>';
if($_POST['pdf_file']!=''){
$email_message.='<tr class="style9">
<td valign="top" class="title02">Itinerary File</td>
<td class="email_message">'.$_POST['pdf_file'].'</td>
</tr>';}
if($_POST['itinerary']!=''){
$email_message.='<tr class="style9">
<td valign="top" class="title02">Itinerary</td>
<td class="email_message">'.$_POST['itinerary'].'<br><br></td>
</tr>';}
$email_message.='
<tr class="style9"><td colspan="2" class="title" bgcolor="#FFFFFF"><strong>FLIGHTS</strong></td></tr>';
if($_POST['date02']!=''){
$email_message.='<tr class="style9">
<td valign="top" class="title02">Date Of Flights</td>
<td class="email_message">'.$_POST['date02'].'</td>
</tr>';}
if($_POST['class_travel']!=''){
$email_message.='<tr class="style9">
<td valign="top" class="title02">Class Of Travel</td>
<td class="email_message">'.$_POST['class_travel'].'</td>
</tr>';}
if($_POST['f_detail']!=''){
$email_message.='<tr class="style9">
<td valign="top" class="title02">Flight Details</td>
<td class="email_message">'.$_POST['f_detail'].'</td>
</tr>';}
if($_POST['airlines']!=''){
$email_message.='<tr class="style9">
<td valign="top" class="title02">Preferred Of Airlines</td>
<td class="email_message">'.$_POST['airlines'].'</td>
</tr>';}
$email_message.='<tr class="style9">
<td colspan="2" valign="top"><div align="center">
</div></td>
</tr>
</table>
</td></tr></table></body>
</html>';
$email_to = "ee_elizebert@hotmail.com"; // Who the email is to
ini_set(SMTP, "mail.sarawakhost.com");
ini_set(smtp_port, "587");
ini_set(sendmail_from, $email);
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
//$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message .= "\n\n";
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";
$ok = mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
$send='<font color=#336600>Feedback sent</font>';
} else {
$send='<font color=#CC3300>Failed to send. Please try again.</font>';
}
}?>