Tema: formulario
Ver Mensaje Individual
  #4 (permalink)  
Antiguo 25/05/2009, 17:48
Avatar de jonak
jonak
 
Fecha de Ingreso: mayo-2009
Mensajes: 34
Antigüedad: 15 años
Puntos: 0
Respuesta: formulario

Código PHP:
<?
function sendemail($from$to$subject$message$attachment) {
    
$fileatt $attachment;
    
$fileatt_type "application/octet-stream";
    
$start=    strrpos($attachment'/') == -strrpos($attachment'//') : strrpos($attachment'/')+1;
    
$fileatt_name substr($attachment$startstrlen($attachment));
    
$email_from $from;
    
$email_subject =  $subject;
    
$email_txt $message;
    
$email_to $to;
    
$headers "From: ".$email_from;
    
    if (
$fileatt!="")
    {
        
$file fopen($fileatt,'rb');
        
$data fread($file,filesize($fileatt));
        
fclose($file); 
    }

    
$semi_rand md5(time()); 
    
$mime_boundary "==Multipart_Boundary_x{$semi_rand}x"
    
$headers .= "\nMIME-Version: 1.0\n" 
            
"Content-Type: multipart/mixed;\n" 
            
" boundary=\"{$mime_boundary}\""
    
$email_message .= "This is a multi-part message in MIME format.\n\n" 
                
"--{$mime_boundary}\n" 
                
"Content-Type:text/html; charset=\"utf-8\"\n" 
               
"Content-Transfer-Encoding: 7bit\n\n" 
    
$email_txt "\n\n"
    
$data chunk_split(base64_encode($data)); 
    if (
$fileatt!="")
        
$email_message .=    "--{$mime_boundary}\n".
                            
"Content-Type: {$fileatt_type};\n".
                            
" name=\"{$fileatt_name}\"\n".
                            
"Content-Transfer-Encoding: base64\n\n".
                            
$data."\n\n".
                            
"--{$mime_boundary}--\n";
    
$ok = @mail($email_to$email_subject$email_message$headers); 
    if (!
$ok
        return 
0;
    else
        return 
1;
}


$aviso="";
if(isset(
$_POST['continente']))       #si se ha definido esta variable
  
{
  if(
$_POST['continente']=="")
    
$aviso'Debe seleccionar un continente.';
  elseif( 
sendemail('[email protected]','[email protected]','asunto de ejemplo''mensaje de ejemplo','') )
    
$aviso'Email enviado!!';
  else
    
$aviso'Error al enviar email';

}


?>
<html>
<head>
</head>
<body>
<div><?=$aviso?></div>
<form action="" method="post">

<select name="continente" onchange="this.form.submit()">
   <option value="">Seleccione continente...</option>
   <option value="Asia">Asia</option>
   <option value="Africa">Africa</option>
</select>
</form>
</body>
</html>