Forum Moderators: coopster

Message Too Old, No Replies

PHPMailer corrupting attached files

anyone use it to send PDF's?

         

doodlebee

1:45 am on Oct 19, 2005 (gmt 0)

10+ Year Member



I'm using PHP mailer to send a form. I need it to send as multipart/mixed, with the body having links in them. (Not an HTML email - but just clickable links in a text e-mail.) I also need to attach a PDF file to send.

Now, I've gotten it to do everything I want in many ways, but every time I try to open the PDF file, it says it's corrupted, probably due to improper decoding.

Here's what I have set for the mail part of the thing:

require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MailClass.inc');
$mail = new FreakMailer();
$mail->IsSMTP();
$mail->From = "info@website.com";
$mail->FromName = "Company Name";
$mail->AddAddress($email,$name);
$mail->AddBCC("info@website.com","Company Name");
$mail->AddReplyTo("info@website2.com","Company Name");
$mail->ContentType = "text/plain; charset=iso-8859-15";
$mail->Subject = "$subject";
$mail->Body = "$body";
$mail->AddStringAttachment($string,"filename.pdf");
$mail->Encoding = "base64";
$mail->Type = "application/pdf";

if(!$mail->Send()) {
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

Does the "filename.pdf" have to be the actual filename on the server? It's a nasty long name, and I thought I could "pretty it up" by calling it something else. But other than that, I don't know why it's coming in corrupted.

By the way, it's on a Windows server.

Any help would be appreciated.

doodlebee

12:58 am on Oct 26, 2005 (gmt 0)

10+ Year Member



Sorry - need to bump this. I was hoping someone knew the answer?

coopster

1:26 pm on Oct 26, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm not familiar with phpmailer itself, but some answers to your questions ...

No, it does not have to be the filename as it exists on the server. You are reading the file in to a string variable anyway so you can give it whichever filename you choose. I would check the mail headers to see where the issue lies. Or try reading in and sending a simple text file attachment first to make sure you have everything coming in correctly. Then move on to the PDF attachment.