Ciao,
tempo fa ho realizzato un form per l'invio mail prendendo qualche suggerimento on-line. Il form funzionava correttamente però ora necessito dell'autenticazione smtp su un server di un cliente.. l'emal arriva con tutti i dati, però l'allegato no..come mai secondo voi? non sono esperto php... grazie per l'aiuto
	
	
	
		
	
	
	
		
	
	
	
		
	
	
	
		
				
			tempo fa ho realizzato un form per l'invio mail prendendo qualche suggerimento on-line. Il form funzionava correttamente però ora necessito dell'autenticazione smtp su un server di un cliente.. l'emal arriva con tutti i dati, però l'allegato no..come mai secondo voi? non sono esperto php... grazie per l'aiuto
		PHP:
	
	<form action="invioMail.php" method="GET">
<input type="hidden" name="destinatario" value="">
<table border="0">
<tr>
  <td>Tua Mail:</td>
  <td><input type="text" name="mittente" value="" /></td>
</tr>
<tr>
<tr>
  <td>Scegli Selezione</td>
  <td>
  <select name="selezione">
  <option value="scelta1">scelta1</option>
  <option value="scelta2">scelta2</option>
  <option value="scelta3">scelta3</option>
  </select>
  </td>
  
</tr>
<tr>
  <td>Oggetto:</td>
  <td><input type="text" name="oggetto" value="" /></td>
</tr>
<tr>
  <td>Messaggio:</td>
  <td><textarea cols="20" rows="4" name="messaggio"></textarea></td>
  </tr>
<tr>
  <td>Allega Curriculum:</td>
  <td><input type="file" name="allegato" /></td>
</tr>
<tr>
  <td colspan="2"><input type="submit" value="Invia" /></td>
</tr>
</table>
</form>
	
		PHP:
	
	  <?php
    include('SMTPconfig.php');
include('SMTPClass.php');
if($_SERVER["REQUEST_METHOD"] == "GET")
{
// Recupero il valore dei campi del form
$destinatario = $_GET['destinatario'];
$mittente = $_GET['mittente'];
$selezione = $_GET['selezione'];
$oggetto = $_GET['oggetto'];
$messaggio = $_GET['messaggio'];
// Valorizzo le variabili relative all'allegato
$allegato = $_FILES['allegato']['tmp_name'];
$allegato_type = $_FILES['allegato']['type'];
$allegato_name = $_FILES['allegato']['name'];
// Creo 2 variabili che riempirò più avanti...
$headers = "From: " . $mittente;
$msg = "";
// Verifico se il file è stato caricato correttamente via HTTP
// In caso affermativo proseguo nel lavoro...
if (is_uploaded_file($allegato))
{
  // Apro e leggo il file allegato
  $file = fopen($allegato,'rb');
  $data = fread($file, filesize($allegato));
  fclose($file);
  // Adatto il file al formato MIME base64 usando base64_encode
  $data = chunk_split(base64_encode($data));
  // Genero il "separatore"
  // Serve per dividere, appunto, le varie parti del messaggio.
  // Nel nostro caso separerà la parte testuale dall'allegato
  $semi_rand = md5(time());
  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  
  // Aggiungo le intestazioni necessarie per l'allegato
  $headers .= "\nMIME-Version: 1.0\n";
  $headers .= "Content-Type: multipart/mixed;\n";
  $headers .= " boundary=\"{$mime_boundary}\"";
  // Definisco il tipo di messaggio (MIME/multi-part)
  $msg .= "This is a multi-part message in MIME format.\n\n";
  // Metto il separatore
  $msg .= "--{$mime_boundary}\n";
  // Questa è la parte "testuale" del messaggio
  $msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
  $msg .= "Content-Transfer-Encoding: 7bit\n\n";
  $msg .= $messaggio . "\n\n";
    $msg .= $selezione . "\n\n";
     
    
  // Metto il separatore
  $msg .= "--{$mime_boundary}\n";
  // Aggiungo l'allegato al messaggio
  $msg .= "Content-Disposition: attachment;\n";
  $msg .= " filename=\"{$allegato_name}\"\n";
  $msg .= "Content-Transfer-Encoding: base64\n\n";
  $msg .= $data . "\n\n";
  
  // chiudo con il separatore
  $msg .= "--{$mime_boundary}--\n";
}
else
{
$msg .= $messaggio . "\n\n";
  $msg .= $selezione . "\n\n";
}
$SMTPMail = new SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $mittente,$destinatario, $oggetto, $msg, $headers);
$SMTPChat = $SMTPMail->SendMail();
echo "<h2>Grazie per averci contattato!</h2>";
  echo "<p>Mail inviata con successo</p>";
}else{
  echo "<p>Errore!</p>";
}
?>
	
		PHP:
	
	<?php
//Server Address
$SmtpServer="..";
$SmtpPort="25";
$SmtpUser="..";
$SmtpPass="..";
?>
	
		PHP:
	
	<?php
class SMTPClient
{
function SMTPClient ($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body)
{
$this->SmtpServer = $SmtpServer;
$this->SmtpUser = base64_encode ($SmtpUser);
$this->SmtpPass = base64_encode ($SmtpPass);
$this->from = $from;
$this->to = $to;
$this->subject = $subject;
$this->body = $body;
	if ($SmtpPort == "") 
	{
	$this->PortSMTP = 25;
		}else{
	$this->PortSMTP = $SmtpPort;
	}
}
                   
function SendMail ()
{
	if ($SMTPIN = fsockopen ($this->SmtpServer, $this->PortSMTP)) 
	{
           
           fputs ($SMTPIN, "EHLO ".$HTTP_HOST."\r\n");  
           $talk["hello"] = fgets ( $SMTPIN, 1024 ); 
                   
		   fputs($SMTPIN, "auth login\r\n");
		   $talk["res"]=fgets($SMTPIN,1024);
			fputs($SMTPIN, $this->SmtpUser."\r\n");
		    $talk["user"]=fgets($SMTPIN,1024);
		    
		    fputs($SMTPIN, $this->SmtpPass."\r\n");
			$talk["pass"]=fgets($SMTPIN,256);
			   	    
           fputs ($SMTPIN, "MAIL FROM: <".$this->from.">\r\n");  
           $talk["From"] = fgets ( $SMTPIN, 1024 );  
           fputs ($SMTPIN, "RCPT TO: <".$this->to.">\r\n");  
           $talk["To"] = fgets ($SMTPIN, 1024); 
           
           fputs($SMTPIN, "DATA\r\n");
			$talk["data"]=fgets( $SMTPIN,1024 );
           
			
			fputs($SMTPIN, "To: <".$this->to.">\r\nFrom: <".$this->from.">\r\nSubject:".$this->subject."\r\n\r\n\r\n".$this->body."\r\n.\r\n");
			$talk["send"]=fgets($SMTPIN,256);
           
           //CLOSE CONNECTION AND EXIT ... 
		   
           fputs ($SMTPIN, "QUIT\r\n");  
           fclose($SMTPIN); 
		 //  
	}  
return $talk;
}        
           
        
}
?>