Помогите разобраться с сабжем. Все сделал, файл отправляется корректно, но есть проблема с mime-типом, никак не могу понять, как его определять. Уже скурил несколько мануалов - недогнал... Как использовать $_FILES при заливке на сервак файла понял, но в данном случае не спасает. Сейчас сервак отправляет файлы text/plain по умолчанию (пока посылает текстовики, но в планах будут картинки, архивы...).
Ниже приведены коды. В mailclass.inc изменил значение по умолчанию $encoding_type в функции attach_file(). С формой в sendfile.html поизголялся, не обращайте внимания.
//sendfile.html
послать файл//testmail.php
include "mailclass.inc";
$mail = new multi_mail;
$mail->from = "admin@eriksona.net";
$mail->to = $to;
$mail->subject = $subjz;
$mail->body = $bodyz;
copy($_SERVER["DOCUMENT_ROOT"].$pathz.$filez,$_SERVER["DOCUMENT_ROOT"]."/test/".$filez.$extz);
$filez=$filez.$extz;
$file_name = $_SERVER["DOCUMENT_ROOT"]."/test/".$filez;
$file_desc = fopen($file_name,"r");
$file_data = fread($file_desc,filesize($file_name));
fclose($file_desc);
echo"Путь к файлу:
$file_name";
$file_size = filesize($file_name);
echo"Размер файла:
$file_size";
chdir($_SERVER["DOCUMENT_ROOT"]."/test/");
$mail -> attach_file($filez,$file_data);
$mail->send_mail();
echo"Отправка на
$mail->to прошла успешно!";
chdir(\'../\');
?>
//mailclass.inc
class multi_mail
{
var $from;
var $parts;
var $to;
var $headers;
var $body;
function multi_mail()
{
$this -> from = "";
$this -> to = "";
$this -> body = "";
$this -> headers = Array();
$this -> subject = "";
}
function attach_file($file_name = "" ,$file_content,$encoding_type = "text/plain")
{
$this -> headers[] = array(
"name" => $file_name,
"content" => $file_content,
"encode" => $encoding_type
);
}
function build_letter($header)
{
$letter = $header["content"];
if ($header["encode"] != "text/plain"):
$letter = chunk_split(base64_encode($letter));
$encoding = "base64";
else:
$encoding = $header["encode"];
endif;
return "Content-Type: ".$header["encode"].
($header["name"]? ".; name = \\"".$header["name"]."\\"" : "")."\\nContent-Transfer-Encoding: $encoding\\n\\n$letter\\n";
}
function set_multipart_mail()
{
$boundary = \'b\'.md5(uniqid(time()));
$multipart = "Content-Type: multipart/mixed; boundary =$boundary\\n\\nThis is a MIME encoded letter\\n\\n--$boundary";
for($step = sizeof($this->headers)-1; $step >=0; $step--)
{
$multipart .= "\\n".$this->build_letter($this->headers[$step])."--$boundary";
}
return $multipart .= "--\\n";
}
function get_full_message()
{
$mime = "";
if (!empty($this->from)):
$mime .= "From: ".$this->from." \\n";
endif;
if (!empty($this->body)):
$this -> attach_file("",$this->body,"text/plain");
$mime .= "MIME-Version: 1.0\\n".$this->set_multipart_mail();
endif;
return $mime;
}
function send_mail()
{
$mime = $this -> get_full_message(false);
mail($this->to,$this->subject,"",$mime);
}
}
?>