Ver Mensaje Individual
  #1 (permalink)  
Antiguo 14/02/2005, 09:00
odilon
 
Fecha de Ingreso: septiembre-2003
Ubicación: Cancun mexico
Mensajes: 50
Antigüedad: 20 años, 7 meses
Puntos: 0
Aprender a adjuntar un archivo http://www.forosdelweb.com/newthread.php?do=newthread&

Hola que tal, he estado buscando la manera de enviar un correo y que este de manera automatica adjunte un archivo, encontre el ejemplo de adjuntar un archivo via formulario, con este ejemplo intente modificarle el codigo para declararle el nombre del archivo y asi lo adjunte automaticamente, pero no me sale en vez de adjuntame el archivo que le pido me manda un txt.

POR FAVOR ALGUIEN QUE ME EXPLIQUE QUE ES LO QUE TENGO QUE HACER PARA QUE SE ADJUNTE DE MANERA AUTOMATICA, LO QUE PRETENDO HACER ES QUE POR MEDIO DE OTRO FORMULARIO INTRODUZCAN SU EMAIL, VALIDO EL EMAIL Y SI ES VALIDO MANDO DE RESPUESTA OTRO EMAIL CON EL ARCHIVO ADJUNTO.

Aqui les pongo el codigo que encontre:

<?
if ($sendmail) {
$mailheaders = "Return-Path: $from\n";
$mailheaders .= "From: $from\n";
//$mailheaders = "From: $from\n";
$mailheaders .= "Reply-To: $from\n";
$mailheaders .= "Cc: $cc\n";
$mailheaders .= "X-Mailer: Expresateweb Email Interface\n";

$msg_body = stripslashes($body);

if ($attach != "none")
{
$file = fopen($attach, "r");
$contents = fread($file, $attach_size);
$encoded_attach = chunk_split(base64_encode($contents));
fclose($file);

$mailheaders .= "MIME-version: 1.0\n";
$mailheaders .= "Content-type: multipart/mixed; ";
$mailheaders .= "boundary=\"Message-Boundary\"\n";
$mailheaders .= "Content-transfer-encoding: 7BIT\n";
$mailheaders .= "X-attachments: $attach_name";

$body_top = "--Message-Boundary\n";
$body_top .= "Content-type: text/plain; charset=US-ASCII\n";
$body_top .= "Content-transfer-encoding: 7BIT\n";
$body_top .= "Content-description: Mail message body\n\n";

$msg_body = $body_top . $msg_body;

$msg_body .= "\n\n--Message-Boundary\n";
$msg_body .= "Content-type: $attach_type; name=\"$attach_name\"\n";
$msg_body .= "Content-Transfer-Encoding: BASE64\n";
$msg_body .= "Content-disposition: attachment; filename=\"$attach_name\"\n\n";
$msg_body .= "$encoded_attach\n";
$msg_body .= "--Message-Boundary--\n";
}
$extra="-f".$from;
mail($to, stripslashes($subject), $msg_body, $mailheaders, $extra);

echo "<h3> Se ha enviado el mail correctamente. www.phpmysql.tk </h3><br>";
}
?>
<p class="titulo">Mandar archivos por un formulario</p>
<br>
<form enctype="multipart/form-data" name=doit action="<? echo $_SERVER['REQUEST_URI'] ?>" method=POST>
<table cellpadding=0 cellspacing=0>
<tr>
<td>Tu e-mail:</td>
<td><input type="text" name="from" size=40 class="form"></td>
</tr>
<tr>
<td>Para:</td>
<td><input type="text" name="to" size=40 class="form"></td>
</tr>
<tr>
<td>Copia a:</td>
<td><input type="text" name="cc" size=40 class="form"></td>
</tr>
<tr>
<td>Copia Blindada a:</td>
<td><input type="text" name="bcc" size=40 class="form"></td>
</tr>
<tr>
<td>Fichero:</td>
<td><input type=file name="attach" size=40 class="form"></td>
</tr>
<tr>
<td>Asunto:</td>
<td><input type="text" name="subject" size=40 class="form"> </td>
</tr>
</table>
Mensaje:<br>
<textarea name="body" rows=15 cols=50 wrap="message" class="form">
</textarea>
<br>
<input type="submit" name="sendmail" value="Enviar" class="form">
</form>