Envío de mail con fichero (attachment)
| From: | Carlos | Date: | Sun, 18 Jul 2004 10:17:26 +0000 |
| Subject: | Envío de mail con fichero (attachment) | ||
| References: | 1 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-50283@lists.php.net to get a copy of this message | ||
Hola de nuevo,
Estoy utilizando el siguiente código (localizado en Hotscripts.com) para
enviar un mensaje desde php con un fichero adjunto. Todo funciona de
maravilla, pero hay un problema con en el cifrado del mensaje (MIME) porque
no consigo pasar acentos y caracteres en español... :-(
¿Alguien sabe como hacerlo?
CODIGO ----------------------
<?php
// --- Create Message Text
$temp.= "\nNombre: " . $HTTP_POST_VARS["Nombre"] . "\n\n";
$temp.= "Apellidos: " . $HTTP_POST_VARS["Apellidos"] . "\n\n";
$temp.= "Email: " . $HTTP_POST_VARS["Email"] . "\n\n";
$temp.= "Referencia: " . $HTTP_POST_VARS["Referencia"] . "\n\n";
$temp.= "Carta de Presentacion: " . $HTTP_POST_VARS["Carta"] .
"\n\n";
// Read POST request params into global vars
$to = $_POST['to'];
$from = $_POST['Email'];
$message = $temp;
// Obtain file upload vars
$fileatt = $_FILES['CV']['tmp_name'];
$fileatt_type = $_FILES['CV']['type'];
$fileatt_name = $_FILES['CV']['name'];
$headers = "From: $from";
if (is_uploaded_file($fileatt)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"UTF-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
// Send the message
$ok = @mail($to, "Nuevo Candidato", $message, $headers);
// -- Send Another Message to SENDER
$message = '
<table width="600" cellspacing="0" cellpadding="5"
border="0"
bgcolor="#EEEEEE">
<tr>
<td><font size="2" face="Verdana"><strong>Oferta
empleo</strong>
</font></td>
</tr>
<tr>
<td bgcolor="#FFFFFF" height="10"></td>
</tr>
<tr>
<td>
<p><font face="verdana" size="2">
Mensaje de confirmación:</font></p>
<p><font face="verdana" size="2">Hemos recibido su solicitud de
empleo y
en breve nos pondremos en contacto con usted. </font></p>
<p><font size="2"
face="verdana">Atentamente,</font></p> <p><font
face="verdana" size="2"> <br>
Departamento de Recursos Humanos<br>
</font></p>
</td>
</tr>
<tr>
<td bgcolor="#FFFFFF" height="10"></td>
</tr>
<tr>
<td bgcolor="#EEEEEE"><div align="right"><font
face="verdana"
size="1"><b>Este mensaje a sido generado
automáticamente.</b></font></div></td>
</tr>
</table>
';
$to = $HTTP_POST_VARS['Email'];
$subject = $HTTP_POST_VARS['titulo'];
$subject .= " ";
$subject .= $HTTP_POST_VARS['nombre'];
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=UTF-8\r\n";
$headers .= "From: LaneFour Strategy & Mangement <rrhh@lanefoursm.com>\r\n";
mail($to, $subject, $message, $headers);
echo "Muchas gracias por su interés.<br>";
echo "<br>Su solicitud ha sido tramitada correctamente y en los próximos
minutos recibirá un mensaje de correo electrónico confirmando su
inscripción.";
?>
/CODIGO ------------------------
Saludos,
Carlos.