Código PHP:
<?
function enviamail($destinatario, $remite, $titulo, $message, $adjunto){
$UN_SALTO="\r\n";
$DOS_SALTOS="\r\n\r\n";
$mensaje="<html><head></head><body bgcolor=\"#0000ff\">";
$mensaje .="<font face=\"Arial\" size=6>".$message." </font>";
$mensaje .="</body></html>";
$separador = "_separador_de_trozos_".md5 (uniqid (rand()));
$cabecera = "Date: ".date("l j F Y, G:i").$UN_SALTO;
$cabecera .= "MIME-Version: 1.0".$UN_SALTO;
$cabecera .= "From: ".$remitente."<".$remite.">".$UN_SALTO;
$cabecera .= "Return-path: ". $remite.$UN_SALTO;
$cabecera .= "Reply-To: ".$remite.$UN_SALTO;
$cabecera .="X-Mailer: PHP/". phpversion().$UN_SALTO;
$cabecera .= "Content-Type: multipart/mixed;".$UN_SALTO;
$cabecera .= " boundary=$separador".$DOS_SALTOS;
// Parte primera -Mensaje en formato HTML
# Separador inicial
$texto ="--$separador".$UN_SALTO;
# Encabezado parcial
$texto .="Content-Type: text/html; charset=\"ISO-8859-1\"".$UN_SALTO;
$texto .="Content-Transfer-Encoding: 7bit".$DOS_SALTOS;
# Contenido de esta parte del mensaje
$texto .= $mensaje;
# Separador de partes
$adj1 = $UN_SALTO."--$separador".$UN_SALTO;
// Parte segunda -Fichero adjunto nº 1
# Encabezado parcial
$adj1 .="Content-Type: ".$_FILES["adjunto"][type]."; name=".$_FILES["adjunto"][name].".$UN_SALTO;
$adj1 .="Content-Disposition: inline; filename="".$_FILES["adjunto"][name]."\"".$UN_SALTO;
$adj1 .="Content-Transfer-Encoding: base64".$DOS_SALTOS;
echo "tipo:".$_FILES["adjunto"][type]."<br>" ;
# lectura del fichero adjunto
$buff = $adjunto;
# codificación del fichero adjunto
$adj1 .=chunk_split(base64_encode($buff));
# Separador de partes
$adj1 = $UN_SALTO."--$separador".$UN_SALTO;
// Unión de las diferentes partes para crear
// el cuerpo del mensaje
$mensaje=$texto.$adj1;
// envio del mensaje
mail($destinatario, $titulo, $mensaje,$cabecera);
echo "mensaje enviado";
}
?>