Ver Mensaje Individual
  #3 (permalink)  
Antiguo 15/04/2016, 11:44
__SDP__
 
Fecha de Ingreso: agosto-2010
Ubicación: santiago, CHILE
Mensajes: 564
Antigüedad: 14 años, 6 meses
Puntos: 9
Respuesta: me obliga a enviar archivo adjunto email

Código PHP:
Ver original
  1. if($_POST && isset($_FILES['mi_archivo'])){
  2.        
  3.         $nombre = $_POST["nombre"];
  4.         $de = '@gmail.com';
  5.         $para = '@gmail.com';
  6.         $asunto = 'asunto';
  7.         $mensaje = 'mensaje';
  8.        
  9.         $file_tmp_name = "";
  10.         $file_name  = "";
  11.         $file_size = "";
  12.         $file_type = "";
  13.         $file_error = "";
  14.         $encoded_content = "";
  15.    
  16.         if($_POST["nombre"]["error"] > 0)
  17.         {
  18.             die('Error al cargar archivo');
  19.         }else{
  20.            
  21.             $file_tmp_name    = $_FILES['mi_archivo']['tmp_name'];
  22.             $file_name        = $_FILES['mi_archivo']['name'];
  23.             $file_size        = $_FILES['mi_archivo']['size'];
  24.             $file_type        = $_FILES['mi_archivo']['type'];
  25.             $file_error       = $_FILES['mi_archivo']['error'];
  26.  
  27.             $handle = fopen($file_tmp_name, "r");
  28.             $content = fread($handle, $file_size);
  29.             fclose($handle);
  30.             $encoded_content = chunk_split(base64_encode($content));       
  31.            
  32.         }  
  33.    
  34.         $boundary = md5("sanwebe");
  35.        
  36.         $cabeceras = "MIME-Version: 1.0\r\n";
  37.         $cabeceras .= "From:".$de."\r\n";
  38.         $cabeceras .= "Reply-To: ".$para."" . "\r\n";
  39.         $cabeceras .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n";
  40.        
  41.         $cuerpo = "--$boundary\r\n";
  42.         $cuerpo .= 'Content-type: text/html; utf8' . "\r\n";
  43.         $cuerpo .= "Content-Transfer-Encoding: base64\r\n\r\n";
  44.         $cuerpo .= chunk_split(base64_encode($mensaje));
  45.        
  46.         $cuerpo .= "--$boundary\r\n";
  47.         $cuerpo .="Content-Type: $file_type; name=\"$file_name\"\r\n";
  48.         $cuerpo .="Content-Disposition: attachment; filename=\"$file_name\"\r\n";
  49.         $cuerpo .="Content-Transfer-Encoding: base64\r\n";
  50.         $cuerpo .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n";
  51.         $cuerpo .= $encoded_content;
  52.        
  53.         $sentMail = @mail($para, $asunto, $cuerpo, $cabeceras);
  54.         if($sentMail)
  55.         {      
  56.             die('Mensaje enviado.');
  57.         }else{
  58.             die('No se ha enviado el mensaje.');  
  59.         }
  60.    
  61.     }