<? 
#####################################################################
#Baseado na vers�o 1.0 do script do Alexander Benatti 
#Foram utilizados exemplos extra�dos do www.php.net 
#Este script � GNU - Licensa P�blica
#---------------------------------------------------
#Nelson R. Moura
#nelson@sitecom.com.br
###################################Inicia o form

if ($action != "upload")
{


print '
<FORM METHOD="post"  ENCTYPE="multipart/form-data">
 <INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="1000000">
 <INPUT TYPE="hidden" NAME="action" VALUE="upload">
 <TABLE BORDER="1">
  
  <TR>
   <TD>From: </TD>
   <TD><input type="text" name="from" size=40><BR></TD>
  </TR>

<TR>
   <TD>To: </TD>
   <TD><input type="text" name="to" size=40><BR></TD>
  </TR

<TR>
   <TD>Subject: </TD>
   <TD><input type="text" name="subject" size=40><BR></TD>
  </TR

<TR>
   <TD>Cc: </TD>
   <TD><input type="text" name="cc" size=40><BR></TD>
  </TR

<TR>
   <TD>Bcc: </TD>
   <TD><input type="text" name="bcc" size=40><BR></TD>
  </TR


  <TR>
   <TD>Body: </TD>
   <TD><TEXTAREA NAME="body" ROWS="10" COLS="50"></ideTEXTAREA></TD>
  </TR>
  
  <TR>
   <TD>File: </TD>
   <TD><INPUT TYPE="file" NAME="anexo"></TD>
  </TR>
  
  <TR>
   <TD COLSPAN="2"><INPUT TYPE="submit" VALUE="Upload"></TD>
  </TR>
 </TABLE>
</FORM>
';


}



###################################Depois de clicar no send

if ($action == "upload")

{
$mime_list = array("html"=>"text/html","htm"=>"text/html", "txt"=>"text/plain", "rtf"=>"text/enriched","csv"=>"text/tab-separated-values","css"=>"text/css","gif"=>"image/gif"); 

$ABORT = FALSE; 

$boundary = "XYZ-" . date(dmyhms) . "-ZYX"; 

$message = "--$boundary\n"; 
$message .= "Content-Transfer-Encoding: 8bits\n";
$message .= "Content-Type: text/plain; charset=\"ISO-8859-1\"\n\n"; 
$message .= $body; 
$message .= "\n"; 

#//attachment file names with full path 
$attachments[1] = $anexo; 
#$attachments[2] = "c:\etc"; 
#$attachments[3] = "c:\etc"; 

//check that the attachment files exist and if so then encode 
foreach ($attachments as $key => $full_path) { 
if ($full_path !='') { 
       if (file_exists($full_path)){ 
       //try to open 
             if ($fp = fopen($full_path,"rb")) { 
                     //get the file name from the path 
                     $filename = array_pop(explode(chr(92),$full_path)); 
                     $contents = fread($fp,filesize($full_path)); 
                     //encode data 
                     $encoded = base64_encode($contents); 
                     //*****SPLIT THE ENCODED DATA***** 
                     $encoded_split = chunk_split($encoded); 
                     fclose($fp); 
                     $message .= "--$boundary\n"; 
                     $message .= "Content-Type: $anexo_type\n"; 
                     $message .= "Content-Disposition: attachment; filename=\"$anexo_name\" \n"; 
                     $message .= "Content-Transfer-Encoding: base64\n\n"; 
                     $message .= "$encoded_split\n"; 
             } 
             else { 
             echo "Cannot open file$key: $filename"; 
             $ABORT = TRUE; 
             } 
       } 
       else { 
       echo "File$key does not exist: $filename"; 
       $ABORT = TRUE; 
       } 

} 
}

$message .= "--$boundary--\r\n"; 

$headers = "MIME-Version: 1.0\n"; 
$headers .= "From: <$from>\r\n"; 
$headers .= "Content-type: multipart/mixed; boundary=\"$boundary\"\r\n"; 

 
$mensagem=mail($to, $subject, $message, $headers);
if ($mensagem) {
    print "Mensagem enviada!";
    
} else {
    print "O envio da mensagem falhou!";
}

}


?>