Advertisement
Guest User

php 2

a guest
Jul 4th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.78 KB | None | 0 0
  1. <?php  
  2. // Recupero il valore dei campi del form  
  3. $destinatario = $_POST['destinatario'];  
  4. $marca = $_POST['marca'];
  5. $modello = $_POST['modello'];
  6. $immatricolazione = $_POST['immatricolazione'];
  7. $carburante = $_POST['carburante'];
  8. $cilindrata = $_POST['cilindrata'];
  9. $nditarga = $_POST['nditarga'];
  10.  
  11. $infosinistro = $_POST['infosinistro'];
  12.  
  13. $nome = $_POST['nome'];
  14. $cognome = $_POST['cognome'];
  15. $telefono = $_POST['telefono'];
  16. $email = $_POST['email'];
  17.  
  18. $datipers = $_POST['datipers'];
  19. $newsletter = $_POST['newsletter'];
  20.  
  21. // Valorizzo le variabili relative all'allegato  
  22. $allegato = $_FILES['allegato']['tmp_name'];  
  23. $allegato_type = $_FILES['allegato']['type'];  
  24. $allegato_name = $_FILES['allegato']['name'];  
  25.  
  26. // Creo 2 variabili che riempirò più avanti...  
  27. $headers = "From: " . $email;  
  28. $msg = "";  
  29.  
  30. // Verifico se il file è stato caricato correttamente via HTTP  
  31. // In caso affermativo proseguo nel lavoro...  
  32. if (is_uploaded_file($allegato))  
  33. {  
  34.   // Apro e leggo il file allegato  
  35.   $file = fopen($allegato,'rb');  
  36.   $data = fread($file, filesize($allegato));  
  37.   fclose($file);  
  38.  
  39.   // Adatto il file al formato MIME base64 usando base64_encode  
  40.   $data = chunk_split(base64_encode($data));  
  41.  
  42.   // Genero il "separatore"  
  43.   // Serve per dividere, appunto, le varie parti del messaggio.  
  44.   // Nel nostro caso separerà la parte testuale dall'allegato  
  45.   $semi_rand = md5(time());  
  46.   $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";  
  47.    
  48.   // Aggiungo le intestazioni necessarie per l'allegato  
  49.   $headers .= "\nMIME-Version: 1.0\n";  
  50.   $headers .= "Content-Type: multipart/mixed;\n";  
  51.   $headers .= " boundary=\"{$mime_boundary}\"";  
  52.  
  53.   // Definisco il tipo di messaggio (MIME/multi-part)  
  54.   $msg .= "This is a multi-part message in MIME format.\n\n";  
  55.  
  56.   // Metto il separatore  
  57.   $msg .= "--{$mime_boundary}\n";  
  58.  
  59.   // Questa è la parte "testuale" del messaggio  
  60.   $msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";  
  61.   $msg .= "Content-Transfer-Encoding: 7bit\n\n";  
  62.   $msg .= $infosinistro . "\n\n";  
  63.  
  64.   // Metto il separatore  
  65.   $msg .= "--{$mime_boundary}\n";  
  66.  
  67.   // Aggiungo l'allegato al messaggio  
  68.   $msg .= "Content-Disposition: attachment;\n";  
  69.   $msg .= " filename=\"{$allegato_name}\"\n";  
  70.   $msg .= "Content-Transfer-Encoding: base64\n\n";  
  71.   $msg .= $data . "\n\n";  
  72.  
  73.   // chiudo con il separatore  
  74.   $msg .= "--{$mime_boundary}--\n";  
  75. }  
  76. else  
  77. {  
  78.   $msg = $messaggio;  
  79. }  
  80.  
  81. // Invio la mail  
  82. if (mail($destinatario, $msg, $headers))  
  83. {  
  84.   echo "<center><p>Mail inviata con successo! Riceverai risposta al più presto. Attendi mentre tornerai all'Home Page.</p></center>";  
  85. }else{  
  86.   echo "<center><p>Errore: La Mail non è stata inviata!</p></center>";  
  87. }  
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement