Код:
<?php
****function send_mail($to, $thm, $html, $path)
****{
*$fp = fopen($path, 'r');
*if (!$fp) exit('Файл не может быть прочитан');
*$file = fread($fp, filesize($path));
*fclose($fp);
*$boundary = "--".md5(uniqid(time()));
*$headers .= "MIME-Version: 1.0\n";
*$headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
*$multipart .= "--$boundary\n";
*$kod = 'windows-1251';
*$multipart .= "Content-Type: text/html; charset=$kod\n";
*$multipart .= "Content-Transfer-Encoding: Quot-Printed\n\n";
*$multipart .= "$html\n\n";
*$message_part .= "--$boundary\n";
*$message_part .= "Content-Type: application/octet-stream\n";
*$message_part .= "Content-Transfer-Encoding: base64\n";
*$message_part .= "Content-Disposition: attachment; filename = \"".$path."\"\n\n";
*$message_part .= chunk_split(base64_encode($file))."\n";
*$multipart .= $message_part."--$boundary\n";
*if (!mail($to, $thm, $multipart, $headers)) exit('К сожалению, письмо не отправлено.');
****}
****if (!empty($_POST))
****{
*if (empty($_POST['mail_to'])) exit("Введите адрес получателя");
*$pattern = "/^[0-9a-z_]+@[0-9a-z_^\.]+\.[a-z]{2,6}$/i";
*if (!preg_match($pattern, $_POST['mail_to'])) exit("Введите адрес получателя в виде [Только зарегистрированные пользователи могут видеть ссылки. ] ");
*$_POST['mail_to'] = htmlspecialchars(stripslashes($_POST['mail_to']));
*$_POST['mail_subject'] = htmlspecialchars(stripslashes($_POST['mail_subject']));
*$_POST['mail_msg'] = htmlspecialchars(stripslashes($_POST['mail_msg']));
*$picture = '';
*if (!empty($_FILES['mail_file']['tmp_name']))
*{
*****$path = $_FILES['mail_file']['name'];
*****if (copy($_FILES['mail_file']['tmp_name'], $path)) $picture = $path;
*}
*$thm = $_POST['mail_subject'];
*$msg = $_POST['mail_msg'];
*$mail_to = $_POST['mail_to'];
*if (empty($picture)) mail($mail_to, $thm, $msg);
*else send_mail($mail_to, $thm, $msg, $picture);
****}
?>
<HTML>
<HEAD>
<title>Смена E-mail</title>
<META Http-Equiv=Content-Type Content="text/html; charset=windows-1251">
</HEAD>
<BODY topmargin=0 marginwidth=0 marginheight=0 leftmargin=0>
<TABLE>
<form enctype='multipart/form-data' method=post>
<TR>
****<TD>To:</TD>
****<TD><INPUT TYPE="text" NAME="mail_to"></TD>
</TR>
<TR>
****<TD>Subject:</TD>
****<TD><INPUT TYPE="text" NAME="mail_subject"></TD>
</TR>
<TR>
****<TD colspan=2>
*Сообщение:
<TEXTAREA NAME="mail_msg" ROWS="8" COLS="50"></TEXTAREA>
****</TD>
</TR>
<TR>
****<TD>Photo:</TD>
****<TD><INPUT TYPE="file" NAME="mail_file"></TD>
</TR>
<TR><TD colspan=2><INPUT TYPE="submit" value='Отправить'></TD></TR>
</TABLE>
</BODY>
</HTML>