Reply to Re: mail() and pdf attachment

Your name:

Reply:


Posted by michael on 10/05/07 05:14

On Oct 4, 6:47 pm, damezumari <jannordgr...@gmail.com> wrote:
> I am trying to send a pdf file as an attachment with the mail()
> function. Unfortunately, the pdf file does not show up as an
> attachment. I get its coding as text along with this:
>
> MIME-Version: 1.0
> Content-Type: multipart/mixed;
> boundary="==Multipart_Boundary_x893cd7b85e299baba9cd7ab913384411x"
>
> --==Multipart_Boundary_x893cd7b85e299baba9cd7ab913384411x
> Content-Type: text/plain; charset=ISO-8859-1
> Content-Transfer-Encoding: 7bit
>
> this is the message
>
> --==Multipart_Boundary_x893cd7b85e299baba9cd7ab913384411x
> Content-Type: application/pdf;
> name="Test file for jmail.pdf"
> Content-Disposition: attachment;
> filename="Test file for jmail.pdf"
> Content-Transfer-Encoding: base64
>
> JVBERi0xLjQKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVyIC9GbGF0ZURlY29k
> ZT4+
>
> ... a lot omitted
>
> wMDU4NiAwMDAwMCBuIAowMDAwMDAxMDc1IDAw
> MDAwIG4gCjAwMDAwMDA3ODAgMDAwMDAgbiAKMDAwMDAwODg3MCAwMDAwMCBuIAp0cmFpbGVyCjw8
> IC9TaXplIDE1IC9Sb290IDEgMCBSIC9JbmZvIDIgMCBSCi9JRCBbPDhCNzc0RDNGRkNGRDI2RjIw
> M0Q0REMyMjk5NjY4NTRDPjw4Qjc3NEQzRkZDRkQyNkYyMDNENERDMjI5OTY2ODU0Qz5dCj4+CnN0
> YXJ0eHJlZgoxMDQ1MwolJUVPRgo=
>
> --==Multipart_Boundary_x893cd7b85e299baba9cd7ab913384411x--
>
> Can anyone tell me what is wrong?
>
> Regards,
>
> Jan Nordgreen

Uhmm I'm not sure, It's hard when you can't see the codes thats send
the email.
But here is PHP code to send a email with file attachment.

It's taken from my tutorial on wiki.greenquery.com


$to_email = "johndoe@hotmail.com";
$subject = "A file from my website";
$filename = $_SERVER["DOCUMENT_ROOT"] . "/files/
myzipfile.zip";
$filetype = "application/octet-stream";
$options = "From: janedoe@hotmail.com";
$text = "Hi John\n\nHere is the zip file i told
you about :-)";

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";


//Read the file
$handle = fopen($filename, 'rb');
$filecontents = fread($handle, filesize($filename));
fclose($handle);

//base64 encode the file
$filecontents = @base64_encode($filecontents);

//Write the mime message
$options .= "\nMIME-Version: 1.0";
$options .= "\nContent-Type: multipart/mixed;\n
boundary=\"". $mime_boundary ."\"\n\n";

$content .= "This is a multi-part message in MIME
format.\n\n";
$content .= "--$mime_boundary\n";


// Adding the text
$content .= "Content-Type: text/html;
charset=iso-8859-1\n";
$content .= "Content-Transfer-Encoding: 8bit\n\n";
$content .= $text . "\n\n";

// Adding the file
$content .= "--". $mime_boundary . "\n";
$content .= "Content-Type: application/octet-stream;
name=\"" . basename($filename) . "\"\n";
$content .= "Content-Transfer-Encoding: base64\n\n";
$content .= chunk_split($filecontents) . "\n\n";
$content .= "--". $mime_boundary . "\n";


//Send the mail
mail($to_email,$subject,$content,$options);


I hope it was of some help to you

//Michael

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация