Foros del Web » Programando para Internet » PHP »

Archivos adjuntos y texto con mail ()

Estas en el tema de Archivos adjuntos y texto con mail () en el foro de PHP en Foros del Web. Hola todos, tengo el siguiente código para enviar formularios con archivos adjuntos a mi email, mi problema es que cuando quiero enviar el formulario SIN ...
  #1 (permalink)  
Antiguo 05/06/2014, 13:16
 
Fecha de Ingreso: junio-2014
Mensajes: 10
Antigüedad: 9 años, 9 meses
Puntos: 0
Archivos adjuntos y texto con mail ()

Hola todos, tengo el siguiente código para enviar formularios con archivos adjuntos a mi email, mi problema es que cuando quiero enviar el formulario SIN el archivo adjunto, aparentemente lo envía pero nunca me llega a el correo, pero cuando lo envió con el adjunto si llega, gracias de antemano. aquí les dejo el código:

Código PHP:
<?php

if ($_POST){ 

$num md5(time());

//MAIL BODY
$body "
<html>
<head>
<title>Monitoreo</title>
</head>
<body style='background:#EEE; padding:30px;'>
<h2 style='color:#767676;'>Monitoreo Grupo Bedoya</h2>"
;

$body .= "
<strong style='color:#0090C6;'>Monitor: </strong>
<span style='color:#767676;'>" 
$_POST["monitor"] . "</span>";

$body .= "
<strong style='color:#0090C6;'>Email: </strong>
<span style='color:#767676;'>" 
$_POST["email"] . "</span>";

$body .= "
<strong style='color:#0090C6;'>Nick: </strong>
<span style='color:#767676;'>" 
$_POST["nick"] . "</span>";

$body .= "
<strong style='color:#0090C6;'>Pagina Monitoreda: </strong>
<span style='color:#767676;'>" 
$_POST["pagina"] . "</span></br>";

$body .= "
<strong style='color:#0090C6;'></strong>
<br><b>" 
$_POST["aclaracion"] . "</b> </br>";

$body .= "
<strong style='color:#0090C6;'></strong>
<br><span style='color:#767676;'>" 
$_POST["recomendacion_modelo"] . "</span> </br>";

$body .= "</body></html>";

$_name=$_FILES["filead"]["name"];
$_type=$_FILES["filead"]["type"];
$_size=$_FILES["filead"]["size"];
$_temp=$_FILES["filead"]["tmp_name"]; 

if( 
strcmp($_name"") ) //FILES EXISTS

$fp fopen($_temp"rb");
$file fread($fp$_size);
$file chunk_split(base64_encode($file)); 

// MULTI-HEADERS Content-Type: multipart/mixed and Boundary is mandatory.
$headers "From: Monitoreo Grupo Bedoya <[email protected]>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; "
$headers .= "boundary=".$num."\r\n";
$headers .= "--".$num."\n"

// HTML HEADERS 
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";
$headers .= "".$body."\n";
$headers .= "--".$num."\n"

// FILES HEADERS 
$headers .= "Content-Type:application/octet-stream "
$headers .= "name=\"".$_name."\"r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; ";
$headers .= "filename=\"".$_name."\"\r\n\n";
$headers .= "".$file."\r\n";
$headers .= "--".$num."--"

}else { 
//FILES NO EXISTS

// HTML HEADERS
$headers "From: Grupo Bedoya \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= "Content-Transfer-Encoding: 8bit\r\n";



// SEND MAIL
mail("[email protected]""Monitoreo grupo bedoya" $body$headers);

echo 
"<div class='ok'>
<strong>El formulario se ha enviado correctamente.</strong></div>"
;

}
?>
  #2 (permalink)  
Antiguo 05/06/2014, 14:02
Avatar de ikaroraul  
Fecha de Ingreso: octubre-2006
Ubicación: La Paz
Mensajes: 391
Antigüedad: 17 años, 5 meses
Puntos: 16
Respuesta: Archivos adjuntos y texto con mail ()

Usa PHPMAILER es mas cómodo trabajar con esa librería.
__________________
Msn: [email protected]
  #3 (permalink)  
Antiguo 05/06/2014, 22:30
 
Fecha de Ingreso: enero-2002
Mensajes: 1.174
Antigüedad: 22 años, 2 meses
Puntos: 21
Respuesta: Archivos adjuntos y texto con mail ()

Cita:
Iniciado por ikaroraul Ver Mensaje
Usa PHPMAILER es mas cómodo trabajar con esa librería.
Nunca he utilizado phpmailer, lo hago con swiftmailer y trabaja OK

Etiquetas: adjuntos, formulario, html, mail
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 23:46.