I tried Answer 1 for a couple of hours with no luck. I found a solution here:
http://www.finalwebsites.com/forums/topic/php-e-mail-attachment-script
Works like a charm- less than 5 min! You might want to change (like I did), the first content type from text/plain to text/html.
Here is my slightly modified version to handle multiple attachments:
function mail_attachment($files, $path, $mailto, $from_mail, $from_name, $replyto, $subject, $message) {
$uid = md5(uniqid(time()));
$header = "From: ".$from_name." <".$from_mail.">
";
$header .= "Reply-To: ".$replyto."
";
$header .= "MIME-Version: 1.0
";
$header .= "Content-Type: multipart/mixed; boundary="".$uid.""
";
$header .= "This is a multi-part message in MIME format.
";
$header .= "--".$uid."
";
$header .= "Content-type:text/html; charset=iso-8859-1
";
$header .= "Content-Transfer-Encoding: 7bit
";
$header .= $message."
";
foreach ($files as $filename) {
$file = $path.$filename;
$file_size = filesize($file);
$handle = fopen($file, "r");
$content = fread($handle, $file_size);
fclose($handle);
$content = chunk_split(base64_encode($content));
$header .= "--".$uid."
";
$header .= "Content-Type: application/octet-stream; name="".$filename.""
"; // use different content types here
$header .= "Content-Transfer-Encoding: base64
";
$header .= "Content-Disposition: attachment; filename="".$filename.""
";
$header .= $content."
";
}
$header .= "--".$uid."--";
return mail($mailto, $subject, "", $header);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…