My problem is that I am trying to send a PDF file from my server after
someone has registered for it. The email message, correct attachment
name and even file type arrive correctly but the file is only 73Bytes
and when you try to open it I get a read error. Can anyone see what is
wrong?

// send an email to the user and then a thanks messaage
        $fileatt = "db/"; // Path to the file                  
        $fileatt_type = "application/pdf"; // File Type 
        $fileatt_name = "webopman.pdf"; // Filename that will be used
for the file as the attachment 
        $email_from = "[EMAIL PROTECTED]"; // Who the email is from 
        $email_subject = "Thank you for downloading the file"; // The
Subject of the email 
        $message_text = "Dear $username, <br>
        Thank you for taking the time to subscribe for our free
file.<br>
        Please find the document attached to this email.<br>"; //
Message that the email has in it 
        $email_to = $email; // Who the email is too 
        $headers = "From: ".$email_from; 
        $file = fopen($fileatt,'r'); 
        $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" . 
        $message_text . "\n\n"; 
        // This may be the problem - not sure what chunk_split or
base64_encode does....
        $data = chunk_split(base64_encode($data)); 

        $email_message .= "--{$mime_boundary}\n" . 
                  "Content-Type: {$fileatt_type};\n" . 
                  " name=\"{$fileatt_name}\"\n" . 
                  //"Content-Disposition: attachment;\n" . 
                  //" filename=\"{$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) 
        { 
        // carry variables into do_html_index() function in output_fns.
        do_html_index($PageTitle, $BodyText, $Picture1, $Picture2,
$CatID, $SECTION_NAME); 
        // put the page footer in position   
        do_html_footer();
        } 
else 
        {
        $PageTitle = "Error!"; 
        $BodyText = "Sorry there has been an error whilst processing
your subscription. Please <a href='[EMAIL PROTECTED]'
class='link'>email us</a> and we will send you a copy of the file as
soon as possible.";
        // carry variables into do_html_index() function in output_fns.
        do_html_index($PageTitle, $BodyText, $Picture1, $Picture2,
$CatID, $SECTION_NAME); 
        // put the page footer in position   
        do_html_footer();
        exit;
        } 

Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to