Hi all,

I am hoping to find an experienced PHP developer to help me troubleshoot an attachment issue with my email script. The user enters his/her email address as part of a form input and this script is supposed to attach a remotely-hosted file (PDF or ZIP) along with some body text. The same script works great for the ZIP file attachment but NOT for PDF. The script does deliver the PDF and the file properly shows up in the email as an attachment -- the problem is when the user attempts to 'open' the PDF. The Adobe Acrobat Reader populates an error stating that the file is corrupted -- which could be do to an encoding issue while sent as an attachment. However, I'm using base64_encoding and I'm using 'application/pdf' as the file type. I admit I'm a bit of a beginner at discerning PHP code -- so I hope that if the community here takes a look at my code line by line -- they can advise me where I am going wrong. I have been doing all kinds of research on this for the past week -- and nothing I've changed has seemed to make a difference. Any help would be greatly appreciated. I'm going to try and include the code below:

PHP Code:
<?php
$file_path 
"http://www.mitchellmetals.net/images/drawings_walkway/w1.pdf"// server path where file is placed
$file_path_type "application/pdf"// File Type
$file_path_name "w1.pdf"// this file name will be used at reciever end 
$headers .= 'Content-type: text/html; charset=utf-8' "\r\n"
$from "noreply@mitchellmetals.net"// E-mail address of sender
$to $_POST['email']; // E-mail address of reciever
$subject "Drawing from Mitchell Metals"// Subject of email
$message "Thank you for downloading the <b>Walkway Canopy with Beams PDF file</b> from mitchellmetals.net. For a free estimate or budget number on a canopy, please email us at <a href='mailto:sales@mitchellmetals.net'>sales@mitchellmetals.net</a>. Please call 770-431-7300 if Mitchell Metals can assist you with your next project."
 
$headers "From: ".$from
 
$file fopen($file_path,'rb');
$data fread($file,filesize($file_path));
fclose($file); 
 
$rand md5(time());
$mime_boundary "==Multipart_Boundary_x{$rand}x"
 
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\""
 
$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" .
$message .= "\n\n"


$data chunk_split(base64_encode($data)); 
 
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$file_path_type};\n" .
" name=\"{$file_path_name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$file_path_name}\"\n" .
"Content-Transfer-Encoding: base64\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";  
 
if(@
mail($to$subject$message$headers)) {
echo 
"File sent!";
 
} else {
echo 
'Failed';
}
?>