PHP PDF attachment doesn't open in outlook

I have a code to generate a PDF and then attach it in a PHP mail script.
The PDf comes through just fine when I open gmail in my browser.

If I open my gmail account through outlook, I see the little attachment symbol, but the email comes through totally blank and I can't access the PDF.
Is there something else I am supposed to change?


    $name        = "Devorah";
    $email       = "ffrid@****";
    $to          = "$name <$email>";
    $from        = "info@*****";
    $subject     = "Application information";
    $mainMessage = "Hi, here's the file.";
    $fileatt     = "application.pdf";
    $fileatttype = "application/pdf";
    $fileattname =  $_POST['lastName'] . "_" . $id .".pdf";
    $headers = "From: $from";

    // File
    $file = fopen($fileatt, 'rb');
    $data = fread($file, filesize($fileatt));
    fclose($file);
   
    // This attaches the 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}\"";
    $message = "This is a multi-part message in MIME format.\n\n" .
    "-{$mime_boundary}\n" .
    "Content-Type: text/plain; charset=\"iso-8859-1\n" .
    "Content-Transfer-Encoding: 7bit\n\n" .
    $mainMessage  . "\n\n";
       
    $data = chunk_split(base64_encode($data));
    $message .= "--{$mime_boundary}\n" .
    "Content-Type: {$fileatttype};\n" .
    " name=\"{$fileattname}\"\n" .
    "Content-Disposition: attachment;\n" .
    " filename=\"{$fileattname}\"\n" .
    "Content-Transfer-Encoding: base64\n\n" .
    $data . "\n\n" .
    "-{$mime_boundary}-\n";
   
    // Send the email
    mail($to, $subject, $message, $headers);
rivkamakAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ganesh Kumar ASr Infrastructure SpecialistCommented:
What happens when you download the file from gmail and open it locally is it opening?
0
NorieAnalyst Assistant Commented:
Can you save the attachment from the Outlook email?
0
rivkamakAuthor Commented:
In out look I see the paperclip but the email is blank and doesn't show any attachement.
In gmail, I can download and open it as a pdf, or open it directly from the gmail account.
0
Julian HansenCommented:
Suggestion: why don't you use the PHPMailer library (https://github.com/PHPMailer/PHPMailer)
It will handle attachments and anything else you can think of with emails without having to mess about with message boundaries and the nuts and bolts of sending emails. It is tried and tested code used by many PHP developers.

I would suggest that you at least try sending your email with PHPMailer and see if you get different results - if you want to go with your own solution this will help to narrow down whether the problem is your implementation or something else.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.