Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Sending PDF attachments using PHPMailer

Posted on 2008-10-15
2
Medium Priority
?
4,862 Views
Last Modified: 2012-05-05
Hi,

Am sending a PDF attachment using PHPMailer like this:

$mail->AddStringAttachment("files/pdf/name.pdf", "name.pdf");

The attachment is sent with the email, but when I try to open, or save it to my machine to open it, get a message saying "couldnt opne file because it's either not a supported file type or because the file has been damaged eg it was sent as an attachment and wasnt correctly encoded....

I tried adjust the method above like this:

$mail->AddStringAttachment("files/pdf/name.pdf", "name.pdf","base64", "application/pdf")

but this didnt work.

The original file (I am sending) does open ok.

Any thoughts greatly appreciated.

Daisy
 
0
Comment
Question by:daisydoos
2 Comments
 
LVL 19

Accepted Solution

by:
BrianGEFF719 earned 500 total points
ID: 22728499
Try:

$mail->AddAttachment(realpath('./files/pdf/name.pdf'),'name.pdf','base64', 'application/pdf');

or:

$mail->AddAttachment(realpath('files/pdf/name.pdf'),'name.pdf','base64', 'application/pdf');
0
 

Author Comment

by:daisydoos
ID: 22728656
Hi Brian,

many thanks - worked a treat!

Cheers,

Daisy
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question