Автор Я.
Если что - будем исправлять.
PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- <?PHP
- #
- /// Pre define some vars ..
- $error=0;
- $mail='';
- $name='';
- $priority=0;
- $recipient=0;
- $file['tmp_name']='';
- $mes='';
- $ok=1;
- $filename='';
- global $destination;
- // Check submitance
- // Checking mail
- if(isset($_POST['mail']) && preg_match("/^[-w.]+@([A-z0-9][-A-z0-9]+.)+([A-z]{2,4}.)?[A-z]{2,4}+$/", $_POST['mail']))
- // Checking sender name
- // Checking if mail & name provided, otherwise send message annonymiously
- // Checking if priority was selected from available list
- $_POST['priority']>5 || $_POST['priority']<1) {echo "Who's form have you submited ? rn"; $ok=0;}
- else $priority = $_POST['priority'];
- // Checking if recipient was selected from available list
- $_POST['recipient']>3 || $_POST['recipient']<1) {echo "Who's form have you submited ? rn"; $ok=0;}
- else $recipient = $_POST['recipient'];
- // --
- // Checking if file was sent
- $file=$_FILES['file'];
- }
- // Formming message text
- switch ($priority){
- case 1: $priority = "extremly important letter."; break;
- case 2: $priority = "very important."; break;
- case 3: $priority = "at least - answer me."; break;
- case 4: $priority = "take a look later."; break;
- case 5: $priority = "take a look sometimes."; break;
- }
- switch ($recipient){
- case 1: $recipient="Hi admin,"; break;
- case 2: $recipient="Hi support,"; break;
- case 3: $recipient="I paid!,"; break;
- }
- function upload($file){
- global $destination;
- $max_size = 1024 * 1024; // 1024 * 1024 = 1 MB
- $valid_extensions = // Allowed file types to be sent us
- array("php","doc","xls","pdf","pot","ppa","pps","gz","gzip","wmf","tar","tgz","zip","rar","ace","css","txt","rtx","log");
- // Checking file size
- if($file['size'] > $max_size)
- {echo "Ma file size is: 1 MB.rn"; return false;}
- // Getting file type
- // Checking file type
- if(($type==='application' || $type==='text' || $type==='video' || $type==='multipart') && !in_array($ext,$valid_extensions))
- {echo "What file is this ?.rn"; return false;}
- if($file['error']!=0) {echo "Error uploading file .rn"; return false;}
- {echo "Error uploading file rn"; return false;}
- return true;
- }
- // Checking whether file was uploaded succesfully
- $up = upload($file);
- function XMail($to, $subj, $text, $filename='',$from = "<site> user@site.com") {
- $head = "From: $fromn";
- $head .= "To: $ton";
- $head .= "Subject: $subjn";
- $head .= "Mime-Version: 1.0n";
- $head .= "Content-Type:multipart/mixed;";
- $head .= "boundary="----------".$un.""nn";
- $zag = "------------".$un."nContent-Type:text/html; charset=windows-1255n";
- $zag .= "Content-Transfer-Encoding: 8bitnn$textnn";
- $zag .= "------------".$un."n";
- $zag .= "Content-Type: application/octet-stream;";
- $zag .= "name="".basename($filename).""n";
- $zag .= "Content-Transfer-Encoding:base64n";
- $zag .= "Content-Disposition:attachment;";
- $zag .= "filename="".basename($filename).""nn";
- }
- // If users input passed all our checks - send the message
- if($ok && XMail("admin@site.com","Mail from site",$message,$filename)) echo "Hurray !! Message sent." ;
- // Deleting temporary file
- }
- ?>