这有点草率。很久以前,我用我在网上找到的代码编写了它/将它捣碎在一起,并且可能已经破坏了它坐在这里拉出私人信息而没有戴眼镜。:-) 我当时通过这种方式学到的东西:chunk_split、连接 (.)、随机分隔符的使用。
<?
$to="x"; // For the file to be sent.
$from="xx"; // For the from line on the received email
$name="name.ext";
$type="application/x-gzip";
$subject="subj"
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
// open the file for a binary read
$file = fopen(**xxxxxxxxxx filepath xxxxxxxxxxxx**,'rb');
// read the file content into a variable
// $data = chunk_split(base64_encode(fread($file,filesize($file))));
// now we encode it and split it into acceptable length lines
//ALREADY DONE, MOVE UP A FEW LINES
// message body
$message = "Here's that File I promised you";
// build headers
$headers = "From: ".$from." \r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";
// put message body in mime boundries
$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" .
$message . "\n\n";
// attachment with mime babble
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$backfile}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
chunk_split(base64_encode(fread($file,filesize(**xxxxxxxxxx filepath xxxxxxxxxxxx**)))) . "\n\n" .
"--{$mime_boundary}--\n";
// close the file
fclose($file);
// send mail
mail($to, $subject, $message, $headers)
?>