I have been working on trying to send a pdf using mime and php. I get the email to send but the attachment is just garbled. I would greatly appreciate any help. I have to looked all over the place for an answer. Hopefully someone will find something for me. The following is what I get in return.
From: Career Choice <info@career-choices.com>
To: Jason <computerlab@career-choices.com>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="Newsletter-Current89502"
This is a multi-part message sent in MIME format.
--Newsletter-Current89502
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Please find attached our current issue of the Working Connection.
We suggest that you have the latest version of Adobe Acrobat Reader.
--Career Choices
Please do not reply to this email. This was sent automatically per your request.
--Newsletter-Current89502
Content-Type: application/pdf; name="CurrentIssue.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="CurrentIssue.pdf"
JVBERi0xLjQNJeLjz9MNCjM2IDAgb2JqPDwvSFsxMDM2IDMxMF0vTGluZWFyaXplZCAxL0Ug
MTE3OTY0L0wgMjQwMjY0L04gNC9PIDM5L1QgMjM5NDk3Pj4NZW5kb2JqDSAgICAgICAgICAg
ICAgICAgDQp4cmVmDQozNiAzNw0KMDAwMDAwMDAxNiAwMDAwMCBuDQowMDAwMDAxMzQ2IDAw
MDAwIG4NCjAwMDAwMDEwMzYgMDAwMDAgbg0KMDAMDAwMTQyNiAwMDAwMCBuDQowMDAwMDAx
NjA1IDAwMDAwIG4NCjAwMDAwMDE4MTQgMDAwMDAgbg0KMDAwMDAwMjA2NyAwMDAwMCBuDQow
MDAwMDAyMzMxIDAwMDAwIG4NCjAwMDAwMDI0MDcgMDAwMDAgbg0KMDAwMDAwMjY0NiAwMDAw
Here is the code for the page.
<?php
$receiver = "jason-hunter@sbcglobal.net";
$sender = "From: info@career-choices.com";
$file_name = "CurrentIssue.pdf";
$file_name = fread(fopen($file_name, 'rb'), filesize($file_name));
$file_name = base64_encode($file_name);
$file_name = chunk_split($file_name, 72);
$mime_boundary = "Newsletter-Current89502";
$message = "From: Career Choice <info@career-choices.com>\r\n";
$message .= "To: Jason <computerlab@career-choices.com>\r\n";
$message .= "MIME-Version: 1.0\r\n";
$message .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"\r\n";
$message .= "This is a multi-part message sent in MIME format.\r\n";
$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$message .= "Content-Transfer-Encoding: 7bit\r\n";
$message .= "\r\n";
$message .= "Please find attached our current issue of the Working Connection.\r\n";
$message .= "We suggest that you have the latest version of Adobe Acrobat Reader.\r\n";
$message .= "--Career Choices\r\n";
$message .= "\r\n";
$message .= "Please do not reply to this email. This was sent automatically per your request.\r\n";
$message .= "--".$mime_boundary."\r\n";
$message .= "Content-Type: application/pdf; name=\"CurrentIssue.pdf\"\r\n";
$message .= "Content-Transfer-Encoding: base64\r\n";
$message .= "Content-Disposition: attachment; filename=\"CurrentIssue.pdf\"\r\n";
$message .= "\r\n";
$message .= $file_name;
$message .= "\r\n";
$message .= "--".$mime_boundary."--\r\n";
$send = mail($receiver, "Current Newsletter", $message, $sender);
?>
<html>
<body>
Done.
</body>
</html>