<?
$websitename="Форма обратной связи с аттачем";
$allowtypes=array("txt", "doc", "docx"); $myemail="name@domen.ru";
$priority="3";
$allowattach="1";
$max_file_size="1024";
$max_file_total="2048";
$submitvalue="Отправить";
$defaultsubject="Резюме";
$use_subject_drop=false;
$subjects=array("Часть 1","Часть 2","Часть 3"); $emails=array("dept_1@domain.com","dept_2@domain.com","dept_3@domain.com"); $thanksmessage="Спасибо! Ваше письмо было отправлено, мы ответим в ближайшее время.";
function get_ext($key)
{
// Cause there the same right?
return $key;
}
function phattach($file,$name)
{
global $boundary;
$message="--".$boundary."\n";
$message.="Content-Type: application/octet-stream; name=\"".$name."\"\n";
$message.="Content-disposition: attachment; filename=\"".$name."\"\n";
$message.="Content-Transfer-Encoding: base64\n";
$message.="\n";
$message.="$str\n";
$message.="\n";
return $message;
}
function clean($key)
{
"/bcc\:/i",
"/Content\-Type\:/i",
"/Mime\-Type\:/i",
"/cc\:/i",
"/to\:/i"
);
return $key;
}
$error="";
$types="";
$sent_mail=false;
$ext_count=count($allowtypes); $i=0;
foreach($allowtypes AS $extension) {
//Gets rid of the last comma
if($i <= $ext_count-2) {
$types .="*.".$extension.", ";
} else {
$types .="*.".$extension;
}
$i++;
}
if($_POST['submit']==true) {
if($allowattach > 0) {
//Loopish
for($i=0; $i <= $allowattach-1; $i++) {
if($_FILES['attachment']['name'][$i]) {
$ext=get_ext($_FILES['attachment']['name'][$i]);
$size=$_FILES['attachment']['size'][$i];
$max_bytes=$max_file_size*1024;
//Check if the file type uploaded is a valid file type.
$error.= "Недопустимое расширение для вашего файла: ".$_FILES['attachment']['name'][$i].", only ".$types." are allowed.<br />";
//Check the size of each file
} elseif($size > $max_bytes) {
$error.= "Ваш файл: ".$_FILES['attachment']['name'][$i]." is to big. Max file size is ".$max_file_size."kb.<br />";
}
} // If Files
} // For
//Tally the size of all the files uploaded, check if it's over the ammount.
$total_size=array_sum($_FILES['attachment']['size']);
$max_file_total_bytes=$max_file_total*1024;
if($total_size > $max_file_total_bytes) {
$error.="Максимальный допустимый размер вашего файла ".$max_file_total."kb<br />";
}
} // If Allowattach
if($error) {
$display_message=$error;
} else {
$subject_count=count($subjects); $email_count=count($emails);
if($subject_count==$email_count) {
$myemail=$emails[$emailsubject];
$emailsubject=$subjects[$emailsubject];
}
}
$yourname=clean($yourname);
$yourmessage=clean($yourmessage);
$youremail=clean($youremail);
$youremail="Резюме";
$headers="From: ".$yourname." <".$youremail.">\n";
$headers.="Reply-To: ".$yourname." <".$youremail.">\n";
$headers.="MIME-Version: 1.0\n";
$headers.="Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n";
$headers.="X-Sender: ".$_SERVER['REMOTE_ADDR']."\n";
$headers.="X-Priority: ".$priority."\n";
$headers.="Return-Path: <".$youremail.">\n";
$headers.="This is a multi-part message in MIME format.\n";
//Message
$message = "--".$boundary."\n";
$message.="Content-Type: text/plain; charset=\"utf-8\"\n";
$message.="Content-Transfer-Encoding: quoted-printable\n";
$message.="\n";
$message.="$yourmessage";
$message.="\n";
//Lets attach to something! =)
if($allowattach > 0) {
for($i=0; $i <= $allowattach-1; $i++) {
if($_FILES['attachment']['name'][$i]) {
$message.=phattach($_FILES['attachment']['tmp_name'][$i],$_FILES['attachment']['name'][$i]);
}
} //For
} // if
// End the message
$message.="--".$boundary."--\n";
// Send the completed message
if(!mail($myemail,$emailsubject,$message,$headers)) {
exit("Произошла ошибка, пожалуйста, сообщите об этом администратору сайта.\n");
} else {
$sent_mail=true;
}
} // else
} // $_POST
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=$websitename?></title>
<style type="text/css">
body{
background-color:#FFFFFF;
font-family: Verdana, Arial, sans-serif;
font-size: 12pt;
color: #000000;
}
.thanks_message{
font-family: Verdana, Arial, sans-serif;
font-size: 11pt;
color: #000000;
}
form{
width: 360px;
padding: 20px;
margin: 50px auto;
background-color:#e5e5e5;
}
</style>
<script>
function runUpload(){
$('#formRezume').submit();
}
</script>
</head>
<body>
<?if($sent_mail!=true) {?>
<form method="post" action="<?=$_SERVER['PHP_SELF'];?>" enctype="multipart/form-data" name="phmailer" id="formRezume" onsubmit="return Checkit(this);">
<?For($i=1;$i <= $allowattach; $i++) {?>
<input name="attachment[]" class="files" type="file" size="30" accept="text/plain,application/pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document" onchange="runUpload()" />
<?}?>
<input type="hidden" name="submit" value="true" />
<input type="submit" value="<?=$submitvalue;?>" />
</form>
<?} Else {?>
<div align="center" class="thanks_message"><?=$thanksmessage;?></div>
<html><head><meta http-equiv='Refresh' content='1; URL=index.php'></head></html>
<?}?>
</body>
</html>