onClick="window.close()"> // Adapted from PHPLIB for PHP 3.0.7+
// By Danke Xie, Peking University
function mail2( $to, $subject, $message, $from, $content_type, $attache="")
{
if ( !empty($from) ) $head = "From: $from\n";
if ( empty($content_type) ) $content_type = "text/plain";
if ( is_array($attache) ) {
$boundary = "===" . md5(uniqid("")) . "===";
$head .= "Mime-Version: 1.0\nContent-Type: multipart/mixed; boundary=\"". $boundary ."\"\n\nThis is a multi-part message in MIME format.\n\n";
$head .= "--" . $boundary . "\n";
$head .= "Content-Type: $content_type\n";
$head .= "\n" . $message . "\n\n";
while ( list( $key, $val ) = each($attache) ) {
$fd = fopen( "./$val", "r" ) or die("unable to open file ./$val");
$contents = chunk_split(base64_encode( fread( $fd, filesize( "./$val" ) ) ));
fclose( $fd );
$head .= "--" . $boundary . "\n";
$head .= "Content-Type: application/octet-stream; name=\"" . basename($val) . "\"\nContent-Transfer-Encoding: BASE64\nContent-Disposition: attachment; filename=\"" . basename($val) . "\"\n";
$head .= "\n" . $contents . "\n\n";
}
$head .= "--" . $boundary . "--\n\n";
}else{
if ( !empty($content_type) ) {
$head .= "Content-Type: $content_type\n";
$head .= "\n" . $message . "\n";
}
}
return mail( "$to", "$subject", "", $head );
}
// Calling sample
mail2("[email protected]","Hello",$message,"[email protected]",
"",array("a.txt","b.pdf"));